Skip to content

Commit 56cf12e

Browse files
committed
crypto: ccp: add new pci device id and modify psp_do_cmd() interface to not rely on sev device
hygon inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IC7KDI CVE: NA --------------------------- add new psp/ccp device id and modify psp_do_cmd() interface to not rely on sev device. Signed-off-by: chench <chench@hygon.cn>
1 parent a14cd83 commit 56cf12e

4 files changed

Lines changed: 40 additions & 23 deletions

File tree

drivers/crypto/ccp/hygon/psp-dev.c

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
/* Function and variable pointers for hooks */
2525
struct hygon_psp_hooks_table hygon_psp_hooks;
26+
static unsigned int psp_int_rcvd;
27+
wait_queue_head_t psp_int_queue;
2628

2729
static struct psp_misc_dev *psp_misc;
2830
#define HYGON_PSP_IOC_TYPE 'H'
@@ -533,65 +535,69 @@ int fixup_hygon_psp_caps(struct psp_device *psp)
533535
return 0;
534536
}
535537

538+
static int psp_wait_cmd_ioc(struct psp_device *psp,
539+
unsigned int *reg, unsigned int timeout)
540+
{
541+
int ret;
542+
543+
ret = wait_event_timeout(psp_int_queue,
544+
psp_int_rcvd, timeout * HZ);
545+
if (!ret)
546+
return -ETIMEDOUT;
547+
548+
*reg = ioread32(psp->io_regs + psp->vdata->sev->cmdresp_reg);
549+
550+
return 0;
551+
}
552+
536553
static int __psp_do_cmd_locked(int cmd, void *data, int *psp_ret)
537554
{
538555
struct psp_device *psp = psp_master;
539-
struct sev_device *sev;
540556
unsigned int phys_lsb, phys_msb;
541557
unsigned int reg, ret = 0;
542558

543-
if (!psp || !psp->sev_data || !hygon_psp_hooks.sev_dev_hooks_installed)
559+
if (!psp || !hygon_psp_hooks.sev_dev_hooks_installed)
544560
return -ENODEV;
545561

546562
if (*hygon_psp_hooks.psp_dead)
547563
return -EBUSY;
548564

549-
sev = psp->sev_data;
550-
551565
/* Get the physical address of the command buffer */
552566
phys_lsb = data ? lower_32_bits(__psp_pa(data)) : 0;
553567
phys_msb = data ? upper_32_bits(__psp_pa(data)) : 0;
554568

555-
dev_dbg(sev->dev, "sev command id %#x buffer 0x%08x%08x timeout %us\n",
556-
cmd, phys_msb, phys_lsb, *hygon_psp_hooks.psp_timeout);
557-
558-
print_hex_dump_debug("(in): ", DUMP_PREFIX_OFFSET, 16, 2, data,
559-
hygon_psp_hooks.sev_cmd_buffer_len(cmd), false);
569+
dev_dbg(psp->dev, "psp command id %#x buffer 0x%08x%08x timeout %us\n",
570+
cmd, phys_msb, phys_lsb, *hygon_psp_hooks.psp_cmd_timeout);
560571

561-
iowrite32(phys_lsb, sev->io_regs + sev->vdata->cmdbuff_addr_lo_reg);
562-
iowrite32(phys_msb, sev->io_regs + sev->vdata->cmdbuff_addr_hi_reg);
572+
iowrite32(phys_lsb, psp->io_regs + psp->vdata->sev->cmdbuff_addr_lo_reg);
573+
iowrite32(phys_msb, psp->io_regs + psp->vdata->sev->cmdbuff_addr_hi_reg);
563574

564-
sev->int_rcvd = 0;
575+
psp_int_rcvd = 0;
565576

566577
reg = FIELD_PREP(SEV_CMDRESP_CMD, cmd) | SEV_CMDRESP_IOC;
567-
iowrite32(reg, sev->io_regs + sev->vdata->cmdresp_reg);
578+
iowrite32(reg, psp->io_regs + psp->vdata->sev->cmdresp_reg);
568579

569580
/* wait for command completion */
570-
ret = hygon_psp_hooks.sev_wait_cmd_ioc(sev, &reg, *hygon_psp_hooks.psp_timeout);
581+
ret = psp_wait_cmd_ioc(psp, &reg, *hygon_psp_hooks.psp_cmd_timeout);
571582
if (ret) {
572583
if (psp_ret)
573584
*psp_ret = 0;
574585

575-
dev_err(sev->dev, "sev command %#x timed out, disabling PSP\n", cmd);
586+
dev_err(psp->dev, "psp command %#x timed out, disabling PSP\n", cmd);
576587
*hygon_psp_hooks.psp_dead = true;
577588

578589
return ret;
579590
}
580591

581-
*hygon_psp_hooks.psp_timeout = *hygon_psp_hooks.psp_cmd_timeout;
582-
583592
if (psp_ret)
584593
*psp_ret = FIELD_GET(PSP_CMDRESP_STS, reg);
585594

586595
if (FIELD_GET(PSP_CMDRESP_STS, reg)) {
587-
dev_dbg(sev->dev, "sev command %#x failed (%#010lx)\n",
596+
dev_dbg(psp->dev, "psp command %#x failed (%#010lx)\n",
588597
cmd, FIELD_GET(PSP_CMDRESP_STS, reg));
589598
ret = -EIO;
590599
}
591600

592-
print_hex_dump_debug("(out): ", DUMP_PREFIX_OFFSET, 16, 2, data,
593-
hygon_psp_hooks.sev_cmd_buffer_len(cmd), false);
594-
595601
return ret;
596602
}
597603

@@ -689,8 +695,12 @@ static irqreturn_t psp_irq_handler_hygon(int irq, void *data)
689695
/* Check if it is SEV command completion: */
690696
reg = ioread32(psp->io_regs + psp->vdata->sev->cmdresp_reg);
691697
if (reg & PSP_CMDRESP_RESP) {
692-
sev->int_rcvd = 1;
693-
wake_up(&sev->int_queue);
698+
psp_int_rcvd = 1;
699+
wake_up(&psp_int_queue);
700+
if (sev != NULL) {
701+
sev->int_rcvd = 1;
702+
wake_up(&sev->int_queue);
703+
}
694704
}
695705
}
696706

drivers/crypto/ccp/hygon/psp-dev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ extern struct hygon_psp_hooks_table {
4646
long (*sev_ioctl)(struct file *file, unsigned int ioctl, unsigned long arg);
4747
} hygon_psp_hooks;
4848

49+
extern struct wait_queue_head psp_int_queue;
50+
4951
#define PSP_MUTEX_TIMEOUT 60000
5052
struct psp_mutex {
5153
uint64_t locked;

drivers/crypto/ccp/psp-dev.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ int psp_dev_init(struct sp_device *sp)
217217
if (ret)
218218
goto e_irq;
219219

220+
if (is_vendor_hygon())
221+
init_waitqueue_head(&psp_int_queue);
222+
220223
/**
221224
* hygon_psp_additional_setup() needs to wait for
222225
* sev_dev_install_hooks() to complete before it can be called.

drivers/crypto/ccp/sp-pci.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,8 @@ static const struct pci_device_id sp_pci_table[] = {
587587
{ PCI_VDEVICE(HYGON, 0x1486), (kernel_ulong_t)&hygon_dev_vdata[2] },
588588
{ PCI_VDEVICE(HYGON, 0x14b8), (kernel_ulong_t)&hygon_dev_vdata[1] },
589589
{ PCI_VDEVICE(HYGON, 0x14a6), (kernel_ulong_t)&hygon_dev_vdata[2] },
590+
{ PCI_VDEVICE(HYGON, 0x14d8), (kernel_ulong_t)&hygon_dev_vdata[1] },
591+
{ PCI_VDEVICE(HYGON, 0x14c6), (kernel_ulong_t)&hygon_dev_vdata[2] },
590592
/* Last entry must be zero */
591593
{ 0, }
592594
};

0 commit comments

Comments
 (0)