From patchwork Wed Dec 14 19:40:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13073422 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3512FC4332F for ; Wed, 14 Dec 2022 19:54:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8B068E0005; Wed, 14 Dec 2022 14:54:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C07E88E0002; Wed, 14 Dec 2022 14:54:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A34308E0005; Wed, 14 Dec 2022 14:54:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8D8CA8E0002 for ; Wed, 14 Dec 2022 14:54:53 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 633AAAB4D4 for ; Wed, 14 Dec 2022 19:54:53 +0000 (UTC) X-FDA: 80241964866.14.81F0E08 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2081.outbound.protection.outlook.com [40.107.93.81]) by imf30.hostedemail.com (Postfix) with ESMTP id 96B1B80006 for ; Wed, 14 Dec 2022 19:54:50 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="htnQpS/i"; spf=pass (imf30.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.81 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671047690; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vcft2Rd+FceGboMQ891metKsRjEQzg2Y4zDqbdImk5c=; b=HlxxHE9rm/NIY9N7zYVRDx5ZXlTyTnM54F+gax7Uwq9R2IQF+bcHaN8ft2iKwBlu12Zgj9 8rg4SWW7DKXsAsnjppKDVD0KiX0c+1Keg11q/pu95dcOE5uTub2EfxIcWrj7m6zAY3Z6/5 npdZTgLbvSIEaulKOh3YYpWdLW8DNVQ= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="htnQpS/i"; spf=pass (imf30.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.81 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1671047690; a=rsa-sha256; cv=pass; b=3q4YT5ufsTl/hZ3/P/PeRLD4vD22/4TuN+/2KHoQQ5Gj9mFFGSx7Wag8GkRAmS8vZj0uot oo10bEm0i0vsSHyZM9Gp8D/SLk1PWcJ8LmBaX+0Z2EePYVNAjoT9gPK0eSY90SEMhzdWTh T9kBfiZ1IIqmubFn+jRytblGVJk/W3Q= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aYHpuQ+XKgqsjOsGApBv1H1P74BAookyNSSAQxaGrlxZR8YN6mzY+hMYxnc9Z7seeucHWQI3YDEnpTs0E39JpqeS+RSM2Y+PiPmkBInjXRdJbxXywFz0zKps7inDnVq3xWbj3AcEeKNwpaqfpyitV30kINNpLL302GzdEdqH/kWeoqHkdbD18ao35VMHN4lHLjc5OXCjUAepIYMvcJltillgJS2mgrxYhMa15TV2QH3ORbDQqquEXFJ5eIA8HRToL50Xx3GdVTLJMzSExnDeTmPwZQ5VIpWVvp2xZ09wVthPB9AoT92Febaxhp3P8//JhNHnt6xxzaQZJy+Jn3sQLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vcft2Rd+FceGboMQ891metKsRjEQzg2Y4zDqbdImk5c=; b=LiQ+DLi/VstbvbLb/fZ2mQYo1Wi4o9xFTpZPx7MwfrterC4RB3b6YPV6c3CKPKlz318fXqgPDHfta6bmz9UjMr+GUo+E9YmQwEixln9Q/drcTvnBXTDgNa75ci4sqKidlT20v5HaD8PPIJB5t5d0ZJlesaU9brvEKFpvs01ZTgJjRePYbJolowmRU8g8apjSpBlTUrzGE7VOp6vNXlKNZY6zUWINJMxGQ5bZyRm3GwWoOa4kO+Qm+1dL1HgZaJ3GuRWVbGlzSJKl8+u17ryhyEn7B7NmVrYNXJHXjp83+Tg0fJr28wdze1e6Kv+Bi1iDDP3VsGgNzloZX/Sq5TUUMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vcft2Rd+FceGboMQ891metKsRjEQzg2Y4zDqbdImk5c=; b=htnQpS/iZG9L72T3ZuQvA1IXq0j3fHd4EkETCc/ar9sIL2GrIl8T6bR9O7ylkSkINzOwUyLud7Tz9BUamdt8AYDckYN9wXzfSbmaGY1rOzw4vz0Hr7YrYXgbQld9IEVHjKFFvRoiEVu+D5ZcSZDv1SWqHTjPZ1ymcfSuIYmF1ZU= Received: from MW4PR03CA0326.namprd03.prod.outlook.com (2603:10b6:303:dd::31) by DS7PR12MB6334.namprd12.prod.outlook.com (2603:10b6:8:95::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.11; Wed, 14 Dec 2022 19:54:48 +0000 Received: from CO1NAM11FT101.eop-nam11.prod.protection.outlook.com (2603:10b6:303:dd::4) by MW4PR03CA0326.outlook.office365.com (2603:10b6:303:dd::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.11 via Frontend Transport; Wed, 14 Dec 2022 19:54:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT101.mail.protection.outlook.com (10.13.175.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5924.11 via Frontend Transport; Wed, 14 Dec 2022 19:54:47 +0000 Received: from localhost (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 14 Dec 2022 13:54:46 -0600 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH RFC v7 30/64] crypto: ccp: Add the SNP_PLATFORM_STATUS command Date: Wed, 14 Dec 2022 13:40:22 -0600 Message-ID: <20221214194056.161492-31-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221214194056.161492-1-michael.roth@amd.com> References: <20221214194056.161492-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT101:EE_|DS7PR12MB6334:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d5db834-61f1-4f2d-22ae-08dade0d0e0d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Uwov9Vcs/wD6TKOtwHMwQqM2KiH5hz7Fk8gA5IeVdFKefJ6l6UB8FN7kn9fXNhgA64t+iJ+RpuNRtzNABNWXhr/gQwARgR7Oix5jVQytRl0X5NLfJkbSdcKjH5ykT/NQRrw0oDdGgJcV9bimYkfrzMT9tVikIXINIf9lOpFUlHVnvziZ+cJLvL3/P8pAkhXomEz/u5P+Fsigk/rsSAtTOAV0uibsnRvFm31vXB/qE4xhlEabEkspKUg7swXXYBSBTQLcZQJxowZCS+SFiE0tHrja63YxgkJ2u8D4pBqJD6D6P5nw6L/g89OTcTmYgnPY9Qd2Etx/W7SqnMNx7XXWhSVopMzWGwuwQbZ2kbFo4DiZ9KYLsTEKGYCJQQ4qUn4P4bzWDC6mJzGdtq7NOz7O1dBzpcyPsdgcmRT2WeVFVLwwIIFlGaYGpfTUJyZ1/Pyx8kepJREYqNhdQl7IlbIhaitQiqz3dTCdyRIdcyWrNTySiUnchFsgIcnysha4C0C8y7q3KjYbpb/Qnolie98jSvirNVP6ug9az2okXllqk9gZX60q4RW3Ga+C7pJuwZn1jqM67P2BMv8iNZHNnMfVl8AVsBMHTGo+EARnZwTXhIlN2J64FBWNdYGVnE1yqZp5QuU4xOXVcWo0tI4j8YyO1563VmhHUF8SHAb1gXf20Q/ihX0LCXvCmgDmiil4B2HhwAc7JX3fmiGMgu+aBHplnzo4dbcPcC6ddzIynbdx1EE= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:CA;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(396003)(39860400002)(346002)(451199015)(46966006)(36840700001)(40470700004)(54906003)(2906002)(316002)(6916009)(81166007)(36860700001)(82310400005)(86362001)(7416002)(8936002)(356005)(7406005)(478600001)(44832011)(83380400001)(40480700001)(5660300002)(8676002)(82740400003)(40460700003)(70586007)(26005)(186003)(1076003)(6666004)(426003)(2616005)(41300700001)(336012)(4326008)(36756003)(70206006)(16526019)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2022 19:54:47.6467 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5d5db834-61f1-4f2d-22ae-08dade0d0e0d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT101.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6334 X-Rspamd-Queue-Id: 96B1B80006 X-Stat-Signature: um44hwdomx9qb56g3e94ffz6ohcjibpy X-Rspam-User: X-Rspamd-Server: rspam08 X-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Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Brijesh Singh The command can be used by the userspace to query the SNP platform status report. See the SEV-SNP spec for more details. Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra Signed-off-by: Michael Roth --- Documentation/virt/coco/sev-guest.rst | 27 ++++++++++++++++ drivers/crypto/ccp/sev-dev.c | 45 +++++++++++++++++++++++++++ include/uapi/linux/psp-sev.h | 1 + 3 files changed, 73 insertions(+) diff --git a/Documentation/virt/coco/sev-guest.rst b/Documentation/virt/coco/sev-guest.rst index bf593e88cfd9..11ea67c944df 100644 --- a/Documentation/virt/coco/sev-guest.rst +++ b/Documentation/virt/coco/sev-guest.rst @@ -61,6 +61,22 @@ counter (e.g. counter overflow), then -EIO will be returned. __u64 fw_err; }; +The host ioctl should be called to /dev/sev device. The ioctl accepts command +id and command input structure. + +:: + struct sev_issue_cmd { + /* Command ID */ + __u32 cmd; + + /* Command request structure */ + __u64 data; + + /* firmware error code on failure (see psp-sev.h) */ + __u32 error; + }; + + 2.1 SNP_GET_REPORT ------------------ @@ -118,6 +134,17 @@ be updated with the expected value. See GHCB specification for further detail on how to parse the certificate blob. +2.4 SNP_PLATFORM_STATUS +----------------------- +:Technology: sev-snp +:Type: hypervisor ioctl cmd +:Parameters (in): struct sev_data_snp_platform_status +:Returns (out): 0 on success, -negative on error + +The SNP_PLATFORM_STATUS command is used to query the SNP platform status. The +status includes API major, minor version and more. See the SEV-SNP +specification for further details. + 3. SEV-SNP CPUID Enforcement ============================ diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 5eb2e8f364d4..10b87ec339aa 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1750,6 +1750,48 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable) return ret; } +static int sev_ioctl_snp_platform_status(struct sev_issue_cmd *argp) +{ + struct sev_device *sev = psp_master->sev_data; + struct sev_data_snp_addr buf; + struct page *status_page; + void *data; + int ret; + + if (!sev->snp_initialized || !argp->data) + return -EINVAL; + + status_page = alloc_page(GFP_KERNEL_ACCOUNT); + if (!status_page) + return -ENOMEM; + + data = page_address(status_page); + if (rmp_mark_pages_firmware(__pa(data), 1, true)) { + __free_pages(status_page, 0); + return -EFAULT; + } + + buf.gctx_paddr = __psp_pa(data); + ret = __sev_do_cmd_locked(SEV_CMD_SNP_PLATFORM_STATUS, &buf, &argp->error); + + /* Change the page state before accessing it */ + if (snp_reclaim_pages(__pa(data), 1, true)) { + snp_mark_pages_offline(__pa(data) >> PAGE_SHIFT, 1); + return -EFAULT; + } + + if (ret) + goto cleanup; + + if (copy_to_user((void __user *)argp->data, data, + sizeof(struct sev_user_data_snp_status))) + ret = -EFAULT; + +cleanup: + __free_pages(status_page, 0); + return ret; +} + static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg) { void __user *argp = (void __user *)arg; @@ -1801,6 +1843,9 @@ static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg) case SEV_GET_ID2: ret = sev_ioctl_do_get_id2(&input); break; + case SNP_PLATFORM_STATUS: + ret = sev_ioctl_snp_platform_status(&input); + break; default: ret = -EINVAL; goto out; diff --git a/include/uapi/linux/psp-sev.h b/include/uapi/linux/psp-sev.h index bed65a891223..ffd60e8b0a31 100644 --- a/include/uapi/linux/psp-sev.h +++ b/include/uapi/linux/psp-sev.h @@ -28,6 +28,7 @@ enum { SEV_PEK_CERT_IMPORT, SEV_GET_ID, /* This command is deprecated, use SEV_GET_ID2 */ SEV_GET_ID2, + SNP_PLATFORM_STATUS, SEV_MAX, };