From patchwork Mon Jun 12 04:25:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13275481 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 0A9C3C7EE25 for ; Mon, 12 Jun 2023 04:35:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 988186B0075; Mon, 12 Jun 2023 00:35:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 938A68E0005; Mon, 12 Jun 2023 00:35:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B4A18E0003; Mon, 12 Jun 2023 00:35:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6E29A6B0075 for ; Mon, 12 Jun 2023 00:35:10 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 353FB1C78BF for ; Mon, 12 Jun 2023 04:35:09 +0000 (UTC) X-FDA: 80892831138.22.39E63DF Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2057.outbound.protection.outlook.com [40.107.94.57]) by imf16.hostedemail.com (Postfix) with ESMTP id 3C2B7180010 for ; Mon, 12 Jun 2023 04:35:04 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=tvRLduvJ; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf16.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.94.57 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; 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=1686544505; 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=M5PixqsA5QQA7A/TruSoyBOLJ81zSazDzW860FjASDM=; b=0fQWDHILSu0NqfFFSwPKNPjZWNUGlS1xGmcfEJCVixKGdLLpyVSO9+SCJ9mq+ojkKIj1rE QWWyj1IefwCGR0d/Dx5TKRI7FUkXVp5K6T9d3Klq2yFDrZKxsi6VinLqcnHfYk0DU4BC2x IwZh/FfmjUreSrycSqo0Aus/xbwtcJ8= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1686544505; a=rsa-sha256; cv=pass; b=VkqTZew2qVHkLvsDIaFkC0gLqeVCnFrMu/LnP1tgWvROWO1GxqXGDJ2r5MYkzO9+u3JBQU iIZ9S2mvJM9Mzd1LuKiKvHm442fmFuEzZgEtyu+7tHIIy2nbAumvjLAeWwxWI5n+DUnXdm agjA3M/ce4dF8lzY+NDXHyQQZcjZyJ8= ARC-Authentication-Results: i=2; imf16.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=tvRLduvJ; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf16.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.94.57 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IQl1tdIjBibIEFuipN+aaTxMV2HbOsbS8Os/ymr3CFj2GR3isN90l5UOC1ER8OK3ebqzSRJyT6BV+AdHrG/Gy0OfZb6djpIw5GI/d2Ik4bajySzpnIfAXcXNtfLPbV6fOhJbHGL/U2NoyMh/8aEHq32OTW9XLtvHIg0nW+K3Z/3Wpk5jaRrg7f7lY1OzH/ycCKxwTv6cd214eWWyJtF+Pn9YvFgHevKYh7x5Tjkv7FAYOWMHmxhhInonPSoZ19FldaqdQ6QeXVK74nu1U4BTPZJavpXY5Q6x9XP9UqW/mTLZzD9z3rcS54f5Otoljnoq5sSFRvI+CY2IKNC2m4XUTw== 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=M5PixqsA5QQA7A/TruSoyBOLJ81zSazDzW860FjASDM=; b=Vt6jpzBLv1fLwWoqkqmAUQ48nRmNkZM5WfBEORVTyqo/1CDxa/GnLgpzplAcXcTYSTfVPtvBrYuhbZGpJKDqknogICTMrgptEC39FH1wTZOCYCG8YQTgy0gBTnXHRZY53tBwKt1tjqwKfcerzkhbwXSg9U2H1qSfRQCGkY1D+QkhFSdj3wcJacV7RuoUN8JkrhpwmSzBpTgtcHsjpr/rhXWO2SHA3vxjPeQ3ImMuThhJbrlrSBTO5hogZKqBGMpajFK81YII7pRsXBZ5A5w1PNf2YA8VPtC8XKXnvflpMsdOWCWuvA/mU007Mko+P7Za+Bhj8rNNONy5hB//oyBNdQ== 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=M5PixqsA5QQA7A/TruSoyBOLJ81zSazDzW860FjASDM=; b=tvRLduvJeIPeBQi00OeM5XF2DKp//bfS7DSmDW6QverV7JVujMsh1uIM3tVuROwUxMn5IJOJckey94lQGzzjL9ehJsmWo7AIoT7PKx2c8qZyy2aUzIGUEgTIVhTetHZZ7pIbS/ZTCyBIfmwQ2qgt+b1bTAPZmV8MxL7b7vAOhHY= Received: from DM6PR06CA0022.namprd06.prod.outlook.com (2603:10b6:5:120::35) by IA1PR12MB8264.namprd12.prod.outlook.com (2603:10b6:208:3f5::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.29; Mon, 12 Jun 2023 04:35:02 +0000 Received: from DM6NAM11FT042.eop-nam11.prod.protection.outlook.com (2603:10b6:5:120:cafe::db) by DM6PR06CA0022.outlook.office365.com (2603:10b6:5:120::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.33 via Frontend Transport; Mon, 12 Jun 2023 04:35:02 +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 DM6NAM11FT042.mail.protection.outlook.com (10.13.173.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6477.29 via Frontend Transport; Mon, 12 Jun 2023 04:35:02 +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.2507.23; Sun, 11 Jun 2023 23:35:01 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH RFC v9 22/51] crypto: ccp: Add the SNP_PLATFORM_STATUS command Date: Sun, 11 Jun 2023 23:25:30 -0500 Message-ID: <20230612042559.375660-23-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230612042559.375660-1-michael.roth@amd.com> References: <20230612042559.375660-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT042:EE_|IA1PR12MB8264:EE_ X-MS-Office365-Filtering-Correlation-Id: e5162c36-bd59-4262-029b-08db6afe633c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: x/nzRJqVhQegFZIFjd69mC9F6yvWmKohIrk/5lP+hGKK9DKXj1CQZxEj0Juf6Vq5uEnjlBtsxXjX3U6OrXcOrc/3s338NMCgHVdIKfGeYW9uSU1Wm2bbjCFpZGPacre19SJPpqHNsXPzNTbA82fPg0eAUrUczSilmZxUjqdj0q+4hoeK/FvER6JzTxCcZcM9A3GtmbQN8B+7ZqBHYwDubssca0oA37d9d2Ggakl8ptwxa9blznG6XN4YA9/eud/uWyps2078qpKJPv7BUVOMiqaJ+v1smTxbDyiCdSWgs8ETvNVD45EFfx18KlNo9/+3w47HJbNhsKzW+7+W/HD5HtfaCuG4v1pft72dgAIy2UPxPJF4Jp5MeIkaG/CElIsQra0Okul1/UNT5Xew3Eub2drOqw4uG2Qg5uManqT5oK51tWcr1AweI3TzwZqLaFdzdnMnxvlscvgGZJ17mEdlpJeSHlDu21qzUObv/kTPLGtDTHhSe2yAvIFfDAjjdeyF0NhDybsRH0IxSMKgxRywZ6HeepF9LWPVTjd2h7X70ozvICtrJAQR1nWWxZHNmfXL2aJ4dK/o2JpValyF1zFg8bn081GUAXDcVLK5GnpNUKg1O0xMsKPXuQowMNmbTQaBlRyBTBgwx3hEh68wp9e2cXS7rEOyvxqi0bj7porylowKT4Wd71d8bnGHWxkqkjD6effA96Kp1hKrH7JxG3NXVqK+8o2RnRJ0KuCMFk2vz98EHUoazo0XF2P2DrrvjSfNiFGwDErpC3rtgw6NS16+4w== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(136003)(376002)(39860400002)(396003)(451199021)(36840700001)(46966006)(40470700004)(40460700003)(70586007)(70206006)(316002)(6666004)(4326008)(6916009)(478600001)(54906003)(36756003)(86362001)(47076005)(36860700001)(1076003)(26005)(426003)(336012)(16526019)(186003)(83380400001)(41300700001)(5660300002)(8936002)(8676002)(7416002)(44832011)(82310400005)(2906002)(40480700001)(7406005)(356005)(2616005)(81166007)(82740400003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2023 04:35:02.1078 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e5162c36-bd59-4262-029b-08db6afe633c 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: DM6NAM11FT042.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8264 X-Stat-Signature: tagdf9ysd4p8e6ym4i5ygraaqruodjw5 X-Rspamd-Server: rspam10 X-Rspamd-Queue-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SuHLBu4ZdUzGtl588YEl6V+M0Q74QfHjw0rStT3TCkgqJ7n5hag6zBzWy6VGVrQf/iaqOYKCInmd0e8Q7DuAKytnOhKxRi8vHSY70GpPHGCMHFVA2RUPU9rfAnq4UOHzQgCW6GCa26MOdwEQUSBHRjJImsZ5saM8OYp13E+DPKIZonFqUU7qpLv5pv6pVzkCPK/GgEXqBEbgc7BJ2onkTGJFmLTrtQBO3TMnBwwkq/gUz/pqjo1Gyf66YBt84/rOrpD0uEqiRyz2zy/+Ebb4KdQTiLEomsjXt2OLy6pFGSrGOslNTlZXC3J5eQkg= X-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 10bb0a7dcfd6..0bfe9721c977 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1767,6 +1767,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_leak_pages(__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; @@ -1818,6 +1860,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 7d8a2dd20273..4dc6a3e7b3d5 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, };