From patchwork Mon Feb 13 10:34:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 56169 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2274362wrn; Mon, 13 Feb 2023 02:42:55 -0800 (PST) X-Google-Smtp-Source: AK7set+B8nGlsiF88ZND1QpBSPdWGPNcWGuGOgy5WlM64FtqTM4Q2BI+2Az2t3vdcTTovpmfuRRB X-Received: by 2002:a17:906:85d2:b0:879:767f:6e45 with SMTP id i18-20020a17090685d200b00879767f6e45mr23319732ejy.17.1676284975816; Mon, 13 Feb 2023 02:42:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676284975; cv=none; d=google.com; s=arc-20160816; b=iWgmn1DpRK5LZoGTFqyY5pYz219cmmQOAaXh897M4o1Dkte32ehKVCLtXDujKamIqs 1ja0i1JlURORll0BHpbaHhHxpY92b/kZAP9qs/BXnZ0cL5P4yVm1YtyAUQV3rCFDgIQt mOV/PNWvb6siDIqoXV6CR1SVu4AXSFITj4Pz+oTSoplyVCSb+6L/Th47X2QCMr4frmV6 VfaNLD9xt6lAjszruRMKE3DrfT/L94mONhhRRLf+TDCeGmhaHPtBb2X8nbD4+gaY97X9 gu7dbxXlt+wxA+0VX/9lKXOfC8RsYNZsMXJFtvQjp0EQ1CfYhnvyharOOURATZpsbUjg 4Zjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=xy4n0PsUoqcPr+Y27mq9kcRn+aDYjUAZLw0FdyzM2VM=; b=RlGzfwUGs8+DJHC6olDJKq70e+6xyBxXiuIMp7z3CFUCxYz05Qh6fBL87gs+NI1/G3 nL7ORXVg2R1DYcGaKgteb7tsTwRQ1ngS4zAllkEdSCG6ufQXzoNACzzgIAxBhC0AFW99 b4+ImkLnepUMu6oIyLvqh4P4EqD0IfqUre/MCx+jg1/TZdkxJ4Rd/gHwAqs6o13NZHAC wdbAaSI3Z5kY/jH5iUKDZH76jh9vpMrUTkIMq7Z1z+YbUmXpUpH7gqQqme5NDKkE59KE 67bo0ZHLS6QOoL0iOO46cw3SaYbKixApPT/HL4DYDL5bMu46cIEMZqsyHy9bBe7ND9eb BaXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=CpP2X4Bq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ft31-20020a170907801f00b008af444b031fsi10784531ejc.203.2023.02.13.02.42.32; Mon, 13 Feb 2023 02:42:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=CpP2X4Bq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229742AbjBMKe7 (ORCPT + 99 others); Mon, 13 Feb 2023 05:34:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231168AbjBMKeq (ORCPT ); Mon, 13 Feb 2023 05:34:46 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 51A861259F; Mon, 13 Feb 2023 02:34:41 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id DECB920C8B77; Mon, 13 Feb 2023 02:34:38 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DECB920C8B77 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1676284480; bh=xy4n0PsUoqcPr+Y27mq9kcRn+aDYjUAZLw0FdyzM2VM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CpP2X4BqcHytwtx7qnNrvxPPHrAXu2hHh1Wa7HYW5nAQo+xEO2DaM1YDITuJBBzSu 41WPUDBqw1nTbnH1BqA9pv3TQmFBaXE2svX+DNk9SdfBSvcXGo9cgdBgVR+0OI3fht 8ubwil6ix/Hz8s4QxF5VEtXGYsjG0Ccyq39FqXyA= From: Jeremi Piotrowski To: linux-kernel@vger.kernel.org Cc: Jeremi Piotrowski , Wei Liu , Dexuan Cui , Tianyu Lan , Michael Kelley , linux-hyperv@vger.kernel.org, Brijesh Singh , Michael Roth , Ashish Kalra , Tom Lendacky , linux-crypto@vger.kernel.org Subject: [RFC PATCH v2 6/7] crypto: ccp - Introduce quirk to always reclaim pages after SEV-legacy commands Date: Mon, 13 Feb 2023 10:34:01 +0000 Message-Id: <20230213103402.1189285-7-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213103402.1189285-1-jpiotrowski@linux.microsoft.com> References: <20230213103402.1189285-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757712195004758379?= X-GMAIL-MSGID: =?utf-8?q?1757712195004758379?= On Hyper-V, the rmp_mark_pages_shared() call after a SEV_PLATFORM_STATUS fails with return code 2 (FAIL_PERMISSION) due to the page having the immutable bit set in the RMP (SNP has been initialized). The comment above this spot mentions that firmware automatically clears the immutable bit, but I can't find any mention of this behavior in the SNP Firmware ABI Spec. Introduce a quirk to always attempt the page reclaim and set it for the platform PSP. It would be possible to make this behavior unconditional as the firmware spec defines that page reclaim results in success if the page does not have the immutable bit set. Signed-off-by: Jeremi Piotrowski --- drivers/crypto/ccp/sev-dev.c | 6 +++++- drivers/crypto/ccp/sp-dev.h | 4 ++++ drivers/crypto/ccp/sp-platform.c | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 6c4fdcaed72b..4719c0cafa28 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -658,8 +658,12 @@ static int __snp_cmd_buf_copy(int cmd, void *cmd_buf, bool to_fw, int fw_err) * no not need to reclaim the page. */ if (from_fw && sev_legacy_cmd_buf_writable(cmd)) { - if (rmp_mark_pages_shared(__pa(cmd_buf), 1)) + if (psp_master->vdata->quirks & PSP_QUIRK_ALWAYS_RECLAIM) { + if (snp_reclaim_pages(__pa(cmd_buf), 1, true)) + return -EFAULT; + } else if (rmp_mark_pages_shared(__pa(cmd_buf), 1)) { return -EFAULT; + } /* No need to go further if firmware failed to execute command. */ if (fw_err) diff --git a/drivers/crypto/ccp/sp-dev.h b/drivers/crypto/ccp/sp-dev.h index c05f1fa82ff4..d50f274462d4 100644 --- a/drivers/crypto/ccp/sp-dev.h +++ b/drivers/crypto/ccp/sp-dev.h @@ -28,6 +28,9 @@ #define CACHE_NONE 0x00 #define CACHE_WB_NO_ALLOC 0xb7 +/* PSP requires a reclaim after every firmware command */ +#define PSP_QUIRK_ALWAYS_RECLAIM BIT(0) + /* Structure to hold CCP device data */ struct ccp_device; struct ccp_vdata { @@ -59,6 +62,7 @@ struct psp_vdata { const unsigned int feature_reg; const unsigned int inten_reg; const unsigned int intsts_reg; + const unsigned int quirks; }; /* Structure to hold SP device data */ diff --git a/drivers/crypto/ccp/sp-platform.c b/drivers/crypto/ccp/sp-platform.c index 1926efbc7b32..937448f6391a 100644 --- a/drivers/crypto/ccp/sp-platform.c +++ b/drivers/crypto/ccp/sp-platform.c @@ -103,6 +103,7 @@ static void sp_platform_fill_vdata(struct sp_dev_vdata *vdata, .feature_reg = pdata->feature_reg, .inten_reg = pdata->irq_en_reg, .intsts_reg = pdata->irq_st_reg, + .quirks = PSP_QUIRK_ALWAYS_RECLAIM, }; memcpy(sev, &sevtmp, sizeof(*sev));