From patchwork Wed Jan 31 23:56:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 195106 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp113689dyc; Wed, 31 Jan 2024 16:24:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IH52msyqw7JHx4ON3Et19XQWwFnNIti9fNtddQR8COR2Mp2kl6cKraWulcHdTHsAlZ4YY9K X-Received: by 2002:a17:902:d4d2:b0:1d9:8f7:dd26 with SMTP id o18-20020a170902d4d200b001d908f7dd26mr3376078plg.5.1706747085680; Wed, 31 Jan 2024 16:24:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706747085; cv=pass; d=google.com; s=arc-20160816; b=sAwFXP8S9s/JCyWXA4x9Miobd3b/14jEnCIwU/VE42oLZje/CJY8BCx3+Vr4/J0BOR r1H2AEZFirEcpriII0DFeMECmlVDqMyTXVJMdd5coaVOzHZ/h0WOcjC0+K2uo1PS1ZF9 nrz14DeJ5UZSitK9XsgDKWDJYh66tHeLns3zDn9KDwGZE1HWfkuEnXOP3WdcbgSl1N0y 3TXsDkgQApiL2QHr9yREYzbZYaJEWI9GjOQkGE4oZ76o7fLPdOcAEzfx9DFqQOWYPMB3 tgBUXhbNJ9gL5TtOUQcb7sYdLfOUTgKzzvHdc33cou4yIAdBC3BIvxY2J9zt5WdfgGbk jwqA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=CQD8xVAMwqMOWi6PTJB0HJDtmdm31D4WNpxMiUSqPiQ=; fh=IWYwZbAId54j9xn8fsQDFqHpDP7OaSnDy1SjQjifh/w=; b=OYutcT6C/5TBihjKCMxzDGC/szczjLMlYxbjmxhex8VOS8lQMjyqQfST1/zyHWYNFi Q9DcOY0BmK6sGSQWQC0wOnXjvWEqYaG5MtQYnJpubzLGuueGiRJAO2r4BK1jLc6YZxMZ j0CU5/Wife9l+wLOu+qVY2ferjCEaVCELJGAqhAqCQmY+l3EkWL/rNNiXpZ/4PdZmz/Y CO03bSU9lorqGzjippQYvDn7PVaP+0ZDd0KpaxriatTvBdLw0FoZhyj7ITJFR0K4x+l7 YbrrtGiOl7OMeXKhB+pAyCyLS3BXMoJjX/TaKas8RHitAhHGKygWuhw4kGjoKqmY0ZLI KcNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QdSWPBrH; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47400-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47400-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCXxs8mG2fRqlzuLMuJQ2/n0BavvmhgsNvPqf9LSns1Kea5DgFeUQMt1yhv3fe0n4FUNR1GKYS9m2lM7Xtq/1Pgmg7gDnQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d19-20020a170902729300b001d93c10adefsi1515315pll.631.2024.01.31.16.24.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 16:24:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47400-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QdSWPBrH; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47400-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47400-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4B546B2D746 for ; Wed, 31 Jan 2024 23:57:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 21BBD3CF6B; Wed, 31 Jan 2024 23:56:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QdSWPBrH" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 832F73B19B for ; Wed, 31 Jan 2024 23:56:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706745376; cv=none; b=bmPwlf2Z+HPBdlREXK4r48UkAMU3RCJnlsU3rpkXiyFQxek+hG6mO5VTuSPufhqX7ZcG02BEpLSmAoAW9WFZzg0OLLVE7hLrcdtQ3OdNYpLH3kFH5uh1Ef6K7OYI22CLoESiviI7TsjCLWv1+60enkGCFfxjZI8A8HeGwQunZ4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706745376; c=relaxed/simple; bh=C2Mp5wDF+w5HYei1nLihykDqJ+peIrgUvLAyytBwPBU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=shkvWmUSeqtHwMaAEJjkeyd8+7h0HENR8YdQIbEuf26g/MkLBYViD697QP//3ym4hWa46VhN9DbQxwZ/8FzHe7/gsALBs8/McWltMD/pvXXsyfLKp5az+vZsbVZyF9nwD62GBypvyDrS7wcwYrDmg00O67uBl5qofud4zRexzMA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QdSWPBrH; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60406626b50so7863977b3.0 for ; Wed, 31 Jan 2024 15:56:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706745373; x=1707350173; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=CQD8xVAMwqMOWi6PTJB0HJDtmdm31D4WNpxMiUSqPiQ=; b=QdSWPBrHomk20lzUGbh0sGV4DlQIZgWvcIOlSeU+SvoGq4ZqXlm3BAeLhfaA8+1lv8 mMJ2JM9bYLHtBdN4+utWr47sJlauQ8DZjxoadFqKfIv/SGjfd53gidHQU1itQuBygbYq 21AC1wKE/mv0pxC4S1u8z521kI9bg8UJFljJdyzhCr6OJ6Si2ZSAtklEO28JduH8XJOc 6F+bljjU5K7OqwB+N+IFWxZAFqI9+FpEHv/9YJiEFDjw73kU07ADdG5AR77DAU2//z5l tdPPHsaa/KdYvbLrzWufCdkIdk8Q8ODIUU9HBsFWn6NYu341dvpFT7LTTvOS76FUzErK epzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706745373; x=1707350173; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CQD8xVAMwqMOWi6PTJB0HJDtmdm31D4WNpxMiUSqPiQ=; b=ND1ZEw5w6HnTojVUCOX7YQTK/lYhF/L6lP4swI3EXtgjM79UC12EQJ31N65RWMTYcY jFvCSxvWpI6dW8CpC6+Z+xfa3Fvyp59cYeJhTvfRdxeVEm9fvyFot/kE07ttiM6dZ7+W g70zPLR1eyT6U/x4qV/+n/MRBYuXcTtqO+z/vEaeld1eJJS9znrZf6BzXMp+I/OvUtUx sCUMWq0Ddy1bLpQS/ndDNbDM6RpVEMik3JC9/TQ93cPXERVF1NQ6vD8MGAanFh+4/826 /oxuhGIXCU7NWY7H3C2b96vM+bLFjUCqbFW3rWgieZ8m+WRjE9etvf7aBhRFKK3HnIkL X7oA== X-Gm-Message-State: AOJu0Yxg7Ix/DN29O6Ulgg3kFiWpcHCQ94lsfUSqoErhk0WTNX3V0VuD F5vyrCTMYPif4rT/G6s6mWevKjvsso9625rv92BSoD0pU+RxkR/bI1Tq+dQiWBlZ97lttyPnArd opQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1385:b0:dc2:3441:897f with SMTP id x5-20020a056902138500b00dc23441897fmr859913ybu.6.1706745373557; Wed, 31 Jan 2024 15:56:13 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 31 Jan 2024 15:56:06 -0800 In-Reply-To: <20240131235609.4161407-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240131235609.4161407-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240131235609.4161407-2-seanjc@google.com> Subject: [PATCH v4 1/4] KVM: SVM: Set sev->asid in sev_asid_new() instead of overloading the return From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ashish Kalra , Tom Lendacky X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789654031962769899 X-GMAIL-MSGID: 1789654031962769899 Explicitly set sev->asid in sev_asid_new() when a new ASID is successfully allocated, and return '0' to indicate success instead of overloading the return value to multiplex the ASID with error codes. There is exactly one caller of sev_asid_new(), and sev_asid_free() already consumes sev->asid, i.e. returning the ASID isn't necessary for flexibility, nor does it provide symmetry between related APIs. Signed-off-by: Sean Christopherson Reviewed-by: Tom Lendacky --- arch/x86/kvm/svm/sev.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index f760106c31f8..7c000088bca6 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -179,7 +179,8 @@ static int sev_asid_new(struct kvm_sev_info *sev) mutex_unlock(&sev_bitmap_lock); - return asid; + sev->asid = asid; + return 0; e_uncharge: sev_misc_cg_uncharge(sev); put_misc_cg(sev->misc_cg); @@ -246,7 +247,7 @@ static void sev_unbind_asid(struct kvm *kvm, unsigned int handle) static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) { struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; - int asid, ret; + int ret; if (kvm->created_vcpus) return -EINVAL; @@ -257,10 +258,9 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) sev->active = true; sev->es_active = argp->id == KVM_SEV_ES_INIT; - asid = sev_asid_new(sev); - if (asid < 0) + ret = sev_asid_new(sev); + if (ret) goto e_no_asid; - sev->asid = asid; ret = sev_platform_init(&argp->error); if (ret) From patchwork Wed Jan 31 23:56:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 195086 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp100753dyc; Wed, 31 Jan 2024 15:58:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IG59yG4307iSUkFdEIN5v0WDR7eU89WpJeongBKLL2bKats1FanusEMSF7yBUhP19tGGAYU X-Received: by 2002:a05:6808:2383:b0:3be:2ff8:c2fd with SMTP id bp3-20020a056808238300b003be2ff8c2fdmr3679019oib.23.1706745497341; Wed, 31 Jan 2024 15:58:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706745497; cv=pass; d=google.com; s=arc-20160816; b=m/EjM6hoJ+b/wm0gISpAmalbS4IerqSdmbDZVGwmB4e2JM3iiZXzrKB0Zua3ox99Bs 9Ta2H3mqpG6OChA0ehojHfgEjjepP7rhcUjBgmLzphHttKoAciLsCSXXt4myViKB74uU jqK0vexfmO7o8Jas7mX0Y8v0p/IGAqvEaWXnA4o4UY+L90DPOcU/uET4wGjVys2UoUpu rGsyAauiZ5e/DZrOuKIE8o3qro2FLKzyDhHDM2ySvuOmNo9Gn8VIOEY4WoM+b5nkULfi fGyD08i3UA6vryn2TYZoMTaTZxBttzAN/a2PMnOfEoO7CMXPpx+4b43aGNi3/wlWuxN3 pmEw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=wDrpEbS6CmtfJ+E5uJL5CN/JlvMOfJl9phijYT5xNg4=; fh=gSRNhBKxQ4nw0fKlokqaiSE4gahvFKJkGm1JvySfH7s=; b=uFZ1+KN8ibpMD7IhbIH7uZXhNw8Bo9nT7t0gtXUUJLMh+7bkwlqLOoAG484A8vk8Zn LpgqOMTJZFKOkD1CWrVq5E3DBLCatTfxCM7U2wIw1ql/w6outXQg9WKYjiPivQ9SBilH Ao6uiUKTdErQ7ZbkS+Q9bqJqUzp5J1+KKB7T+0nyVZ+DkOQOveDYuhhNQ7cxeSwgCxf7 /t9KNPi5qmS1TBfe5d6jqL2mAS7mrSkM67FP2OHOAhBS+Bcc1X2d5Ex0lN29aadjm9TN 9ly6o+su9UaN24w+x3gRZBJLuiT1GOJsOYwgjftR0ZXkmLe/FNTuOS3y09351Sm+0oed HbAg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nE6k6GwO; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47402-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47402-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCX+yYTbddvVArq4gNWmIwsV4bGcp+D4dUehYVnYCeCknqoLUtDSdh3p8RcRDuNytVgd/wvHWS5cTTi6mgogRWdOzsPuZg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g2-20020ac87f42000000b0042ab1abe300si5547680qtk.69.2024.01.31.15.58.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 15:58:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47402-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nE6k6GwO; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47402-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47402-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 026251C233D3 for ; Wed, 31 Jan 2024 23:58:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CCB2E3FE5B; Wed, 31 Jan 2024 23:56:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nE6k6GwO" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 779C43BB29 for ; Wed, 31 Jan 2024 23:56:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706745380; cv=none; b=XK9FbRp6VWzLNFvnapMu9ZonOztMWaydFh0X1MxMLdiz8TCSExohGSWaVRFSQQpJQveQmztvvxIlk0Du3R7d1POHu42PA0cSV6JUqmxssy4Nzn11aKvF83rTA/K7bI+QveS7ajEjFF7Cq2tsA/KmyR1Tjf8YWF7YU32s/2wR5Wc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706745380; c=relaxed/simple; bh=Y2eTrWyIvoI9BY4Vorbbz847bJmJSiZQnQACclMHzyM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=osB5s5z9ZqaGOL0C2iGLZ6sCL3CTKYb5G9UJoRYwtu4GGGMG2RVfiI4kOfgce2L5gVNvPiShNuGU1RxtH448dA+sJHRG2kezbGNiSCs/Bh/UCu0jiirON+iSreji2YdP9ZUyPccqLnLg5/ax+PBl+yPCcroB56F3awVn6zugaw0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nE6k6GwO; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6040597d005so6844047b3.2 for ; Wed, 31 Jan 2024 15:56:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706745375; x=1707350175; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=wDrpEbS6CmtfJ+E5uJL5CN/JlvMOfJl9phijYT5xNg4=; b=nE6k6GwOgPbzqBzDgNDXdpItFoEceXrLJfmpvHlwcgPlaUbtKdpXDQIZbJkpbJ8XN3 YQlCPCTG49J0ezo4eRtgwoplBXIgraqjEuogEM3OgshhL6XRok1l3lxP4ssI6pcF0jWA A4TAD/fV0uJ2mhwU61jYzyU3vt0XMy2H7Zez8nmR7AUsXycLTttGvyrNd+B8YPQ64nvb XpdM6zlwXClEJlVlrCwYeGgzZ9DZQwIeWKEyXI4YPsqn8G86B6ilsOjetPE7zbR1Ug6K 2zFRg1EkP/oXdeppVZan34sZ5Uy9ohgNVVFIDNPIdwVFABl7gBJywozQ7lki4uk8ybMh 2XgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706745375; x=1707350175; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wDrpEbS6CmtfJ+E5uJL5CN/JlvMOfJl9phijYT5xNg4=; b=sfI3ptrBa2WtwlTKjH9Ic1EmLYOdfD5irPOkiXPQ/H19tbnsUIqTvgB7iWW9GuuLws 68jKKSnLAmRN1q8daoWP9/XB9FOlTYebzOaMCrhWtxRzvE8T47RAG2rghg0As1KTW8RH Owv9o3u8KSBdXVU8/mgVpt7PSZCMdnMNlWOjwdc2n11ERzRz6eKaOgFbxyhRDl7xGSUw smX1B7GFFE3gUdSIB7trB6Bq0TACA/d2Z3drGLnLco3SfyX09ewN0KvdZBWlR5McO+5K QG/iFJ+LKUVhM6CVa9/ANRwd4M0VHife+5yZCrmNKJN3Ps26IhSskg7e6GB1Kdxdfw88 OHHA== X-Gm-Message-State: AOJu0YzgCRqdd7EgDs/eocBPMfy4Ezc+QDS4nupVymLF9eSjQsKIJjkj qJaFJVh8RtCb997FG/A/VsmYHl0tiYd7Vgto8yX8G2amcA8jRCU3biqpr9QdrZSveNSBDMb+BuT kBA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:9e:b0:603:ea10:c37c with SMTP id be30-20020a05690c009e00b00603ea10c37cmr719982ywb.7.1706745375516; Wed, 31 Jan 2024 15:56:15 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 31 Jan 2024 15:56:07 -0800 In-Reply-To: <20240131235609.4161407-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240131235609.4161407-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240131235609.4161407-3-seanjc@google.com> Subject: [PATCH v4 2/4] KVM: SVM: Use unsigned integers when dealing with ASIDs From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ashish Kalra , Tom Lendacky X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789652366857030731 X-GMAIL-MSGID: 1789652366857030731 Convert all local ASID variables and parameters throughout the SEV code from signed integers to unsigned integers. As ASIDs are fundamentally unsigned values, and the global min/max variables are appropriately unsigned integers, too. Functionally, this is a glorified nop as KVM guarantees min_sev_asid is non-zero, and no CPU supports -1u as the _only_ asid, i.e. the signed vs. unsigned goof won't cause problems in practice. Signed-off-by: Sean Christopherson Reviewed-by: Tom Lendacky --- arch/x86/kvm/svm/sev.c | 18 ++++++++++-------- arch/x86/kvm/trace.h | 10 +++++----- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 7c000088bca6..04c4c14473fd 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -84,9 +84,10 @@ struct enc_region { }; /* Called with the sev_bitmap_lock held, or on shutdown */ -static int sev_flush_asids(int min_asid, int max_asid) +static int sev_flush_asids(unsigned int min_asid, unsigned int max_asid) { - int ret, asid, error = 0; + int ret, error = 0; + unsigned int asid; /* Check if there are any ASIDs to reclaim before performing a flush */ asid = find_next_bit(sev_reclaim_asid_bitmap, nr_asids, min_asid); @@ -116,7 +117,7 @@ static inline bool is_mirroring_enc_context(struct kvm *kvm) } /* Must be called with the sev_bitmap_lock held */ -static bool __sev_recycle_asids(int min_asid, int max_asid) +static bool __sev_recycle_asids(unsigned int min_asid, unsigned int max_asid) { if (sev_flush_asids(min_asid, max_asid)) return false; @@ -143,8 +144,9 @@ static void sev_misc_cg_uncharge(struct kvm_sev_info *sev) static int sev_asid_new(struct kvm_sev_info *sev) { - int asid, min_asid, max_asid, ret; + unsigned int asid, min_asid, max_asid; bool retry = true; + int ret; WARN_ON(sev->misc_cg); sev->misc_cg = get_current_misc_cg(); @@ -188,7 +190,7 @@ static int sev_asid_new(struct kvm_sev_info *sev) return ret; } -static int sev_get_asid(struct kvm *kvm) +static unsigned int sev_get_asid(struct kvm *kvm) { struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; @@ -284,8 +286,8 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) static int sev_bind_asid(struct kvm *kvm, unsigned int handle, int *error) { + unsigned int asid = sev_get_asid(kvm); struct sev_data_activate activate; - int asid = sev_get_asid(kvm); int ret; /* activate ASID on the given handle */ @@ -2312,7 +2314,7 @@ int sev_cpu_init(struct svm_cpu_data *sd) */ static void sev_flush_encrypted_page(struct kvm_vcpu *vcpu, void *va) { - int asid = to_kvm_svm(vcpu->kvm)->sev_info.asid; + unsigned int asid = to_kvm_svm(vcpu->kvm)->sev_info.asid; /* * Note! The address must be a kernel address, as regular page walk @@ -2630,7 +2632,7 @@ void sev_es_unmap_ghcb(struct vcpu_svm *svm) void pre_sev_run(struct vcpu_svm *svm, int cpu) { struct svm_cpu_data *sd = per_cpu_ptr(&svm_data, cpu); - int asid = sev_get_asid(svm->vcpu.kvm); + unsigned int asid = sev_get_asid(svm->vcpu.kvm); /* Assign the asid allocated with this SEV guest */ svm->asid = asid; diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h index 83843379813e..b82e6ed4f024 100644 --- a/arch/x86/kvm/trace.h +++ b/arch/x86/kvm/trace.h @@ -732,13 +732,13 @@ TRACE_EVENT(kvm_nested_intr_vmexit, * Tracepoint for nested #vmexit because of interrupt pending */ TRACE_EVENT(kvm_invlpga, - TP_PROTO(__u64 rip, int asid, u64 address), + TP_PROTO(__u64 rip, unsigned int asid, u64 address), TP_ARGS(rip, asid, address), TP_STRUCT__entry( - __field( __u64, rip ) - __field( int, asid ) - __field( __u64, address ) + __field( __u64, rip ) + __field( unsigned int, asid ) + __field( __u64, address ) ), TP_fast_assign( @@ -747,7 +747,7 @@ TRACE_EVENT(kvm_invlpga, __entry->address = address; ), - TP_printk("rip: 0x%016llx asid: %d address: 0x%016llx", + TP_printk("rip: 0x%016llx asid: %u address: 0x%016llx", __entry->rip, __entry->asid, __entry->address) ); From patchwork Wed Jan 31 23:56:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 195085 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp100680dyc; Wed, 31 Jan 2024 15:58:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqCLSS7VTQ2mr+4ROG3Qx93PqOZJ+dS6bjFkoi5+6GFTn53XB0tIUn76zIXlsihp5f5VW2 X-Received: by 2002:a05:620a:1013:b0:783:f8aa:7546 with SMTP id z19-20020a05620a101300b00783f8aa7546mr1156635qkj.28.1706745485599; Wed, 31 Jan 2024 15:58:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706745485; cv=pass; d=google.com; s=arc-20160816; b=aqjXRHqz3E9YSmL4G962ATZZ/66VYnol3y3SyF03FIw86gOU9Qjn/7PBt2IGOsT01y fl6//BszPd+/LE2ZVqOx1YYfYQflmHrwaYoQ6s8uMTYi6U/WSyqvq6AXtcFH/bgIihqL h1LtxEpQ+0v2kW8r8r8aF7RohWvN/uKWZpaXj3h5cTC2S3cxdy07V0X0Wb7zW9HKNbwU 3xBNBUQo6bTjRCMB/NwVaPPvaT4HlJ8JJw0lSMJi2bwxVXCUbqTnj0k5RNg9hTAEEjhe A6XJKSXeGYpBa+2tq6P0usSyqAqQoczdY3jzDHUbim1mhVoQHlyWYt3cHC07HrpvjYTp i3bw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=/WObf82Vf/Y5MR7jXp0Gt7NYNHTt/4hLoEW6luDmRxk=; fh=Izpkwk3bvrc5NZQEgAx1gSMQkSldZX+1NCtHqFRFwDk=; b=0UCGiOGBuyj8oayHdnAS6+pXNi1yR/2OWL23e7h1egSwp/lTXm1UW06KnHp02plTfi yRraQSnllFcU5ZN9ewEPzFrVYaxQ2z+8TjmR4A1FNZOxqEnMwka8z8sXQNx2TIY3MRPm NlKhGrgEv/cyQIKHNZ1sQjAQU7zpHEsddf+/bAs9RSZeIcrgSaeGhdT1RAxaYMvXR3oE /uDzHdZiGP2g4X7ZxvR6rN3U/2jWrUGkO42RyUu0vElqg+jlmWHLppxLwQdcYljILM+s G0rvE4EyKpGESoLFXmteZd2stTHlqJZeLT5oYdfLk182UIQILH1X9zCr8SsJQ3BSVYOK TE/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sahZiboW; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47401-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47401-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCWnNC3GHnqUMbC9GlsNxjSpUwrW1JNpWTLuweY8hfIyyqp5CzzLW6leJVP4UYQwkz3ZadYB8XKItRSfbkuyOM4g+l3pYA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d6-20020a05620a136600b00783ddf8c341si12224459qkl.198.2024.01.31.15.58.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 15:58:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47401-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sahZiboW; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47401-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47401-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 558981C236DE for ; Wed, 31 Jan 2024 23:58:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F172C3FE24; Wed, 31 Jan 2024 23:56:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sahZiboW" Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41F083AC34 for ; Wed, 31 Jan 2024 23:56:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706745379; cv=none; b=GEfr3aHvhSG7D1JWvqsQqINZLU3M8aAVbNtS0T7RtXpes2Jr9glFGmvx02yW7kJslsdcRUsiGXt8EVPSe/vXigYju91oE1DV5VpgWQEihER597CEZwdf2LqLACFjyJ9hwZ/3I3oxu6/6oUakceRP7GMVsrU0o1NsWKdvZzyIoHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706745379; c=relaxed/simple; bh=D1nog3XCAS5QFsKZW5HVf+ENkuPBa0MU2IJSYf8wk+o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZXcFHfbmHODjjZOi8juaeSF/9EXhrm5fMGi6CRvG5DWTltTij9mchDKkMDnBmKZo6XFhkj01iK3GuN4fu4mRu/S/qE9f4RTjnfJQJj6ebmBfx9AE/JPTwCWc3v9/OtZXazQT7p4eOTkpiuS5SZAjFnRaKTFXaZDHnj9JrPO99PI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=sahZiboW; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-5d63c7c4248so1295438a12.0 for ; Wed, 31 Jan 2024 15:56:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706745377; x=1707350177; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=/WObf82Vf/Y5MR7jXp0Gt7NYNHTt/4hLoEW6luDmRxk=; b=sahZiboWzyFipkcxsmrChqjVG6r4CmV41tCxJfv66ChItU88vt2YhWaAf3BEfazat/ ks33WPMLlJcvZ+7xrnd3VxpkmT3n2hyNPBe3Ze0oYDuLB0NLqgxD3Bva/ke1oSUpl5G5 KjyVltb07236dh33TY80r3vr1ygh0JKOAIPaKW1Ear7X+qIjzVEWpKMJrmo6POaxlGyG vYLPzGygHwJayxw5nMLaPq9bI02ODUrkai9Sz8GJm4BZxcL8x8A6IT/1VPxrLrJWNq20 56pun4w47b6HnckQE7LytsdHAS6HzwPvAdKP48oTs8b8sGTpf04mCHh/HSoSxwNHIlrG 0gvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706745377; x=1707350177; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/WObf82Vf/Y5MR7jXp0Gt7NYNHTt/4hLoEW6luDmRxk=; b=HUnDBD3pVPB8vBQkWr8PNA0rkUj3LOPWkE+YJI5HjWA9xY0l3ib/sWTl5ludDCjLg2 jZDOsbyp/MwzNSzhO8KbT3ppKhMF3KAEJzdCUGZ+9xa4IIvL7x59YDRxkEHRUu6bLh1g tNTVz47OJpaliO4gOHrQJvTGuUnQQEyy9iZnLTx1d42xvYNdftLisVdzsGQVH5fgLUjT sUZLNvk/Bas5GCU1Zs7FldBpLvIf9SrhEXhPmS5W6FUfgSGpK7XtCiZkKHPbmwefuL2F cXM9UF9XpPGpemgeuHmxhlzYTw+ObW5wRa16sGjjbxPPeqC4QgF3yR8273Y8iXM2w0hT kELA== X-Gm-Message-State: AOJu0YzzI3/ztfzxHKl8yoCMM/dqE/n8wE/01mwDK7GV6YgdXo8v5Bxg 2Dijgsw2goRx3QOpUk1saQKBkcXkEfULLfYZ8a5042henc7oYK79Fc8U4MVaYMMFFGgsTR5pEMC sRg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:2bc8:b0:295:6834:b941 with SMTP id n8-20020a17090a2bc800b002956834b941mr45398pje.1.1706745377422; Wed, 31 Jan 2024 15:56:17 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 31 Jan 2024 15:56:08 -0800 In-Reply-To: <20240131235609.4161407-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240131235609.4161407-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240131235609.4161407-4-seanjc@google.com> Subject: [PATCH v4 3/4] KVM: SVM: Add support for allowing zero SEV ASIDs From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ashish Kalra , Tom Lendacky X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789652354330887286 X-GMAIL-MSGID: 1789652354330887286 From: Ashish Kalra Some BIOSes allow the end user to set the minimum SEV ASID value (CPUID 0x8000001F_EDX) to be greater than the maximum number of encrypted guests, or maximum SEV ASID value (CPUID 0x8000001F_ECX) in order to dedicate all the SEV ASIDs to SEV-ES or SEV-SNP. The SEV support, as coded, does not handle the case where the minimum SEV ASID value can be greater than the maximum SEV ASID value. As a result, the following confusing message is issued: [ 30.715724] kvm_amd: SEV enabled (ASIDs 1007 - 1006) Fix the support to properly handle this case. Fixes: 916391a2d1dc ("KVM: SVM: Add support for SEV-ES capability in KVM") Suggested-by: Sean Christopherson Signed-off-by: Ashish Kalra Cc: stable@vger.kernel.org Acked-by: Tom Lendacky Link: https://lore.kernel.org/r/20240104190520.62510-1-Ashish.Kalra@amd.com Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/sev.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 04c4c14473fd..38e40fbc7ea0 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -144,10 +144,21 @@ static void sev_misc_cg_uncharge(struct kvm_sev_info *sev) static int sev_asid_new(struct kvm_sev_info *sev) { - unsigned int asid, min_asid, max_asid; + /* + * SEV-enabled guests must use asid from min_sev_asid to max_sev_asid. + * SEV-ES-enabled guest can use from 1 to min_sev_asid - 1. + * Note: min ASID can end up larger than the max if basic SEV support is + * effectively disabled by disallowing use of ASIDs for SEV guests. + */ + unsigned int min_asid = sev->es_active ? 1 : min_sev_asid; + unsigned int max_asid = sev->es_active ? min_sev_asid - 1 : max_sev_asid; + unsigned int asid; bool retry = true; int ret; + if (min_asid > max_asid) + return -ENOTTY; + WARN_ON(sev->misc_cg); sev->misc_cg = get_current_misc_cg(); ret = sev_misc_cg_try_charge(sev); @@ -159,12 +170,6 @@ static int sev_asid_new(struct kvm_sev_info *sev) mutex_lock(&sev_bitmap_lock); - /* - * SEV-enabled guests must use asid from min_sev_asid to max_sev_asid. - * SEV-ES-enabled guest can use from 1 to min_sev_asid - 1. - */ - min_asid = sev->es_active ? 1 : min_sev_asid; - max_asid = sev->es_active ? min_sev_asid - 1 : max_sev_asid; again: asid = find_next_zero_bit(sev_asid_bitmap, max_asid + 1, min_asid); if (asid > max_asid) { @@ -2234,8 +2239,10 @@ void __init sev_hardware_setup(void) goto out; } - sev_asid_count = max_sev_asid - min_sev_asid + 1; - WARN_ON_ONCE(misc_cg_set_capacity(MISC_CG_RES_SEV, sev_asid_count)); + if (min_sev_asid <= max_sev_asid) { + sev_asid_count = max_sev_asid - min_sev_asid + 1; + WARN_ON_ONCE(misc_cg_set_capacity(MISC_CG_RES_SEV, sev_asid_count)); + } sev_supported = true; /* SEV-ES support requested? */ @@ -2266,7 +2273,9 @@ void __init sev_hardware_setup(void) out: if (boot_cpu_has(X86_FEATURE_SEV)) pr_info("SEV %s (ASIDs %u - %u)\n", - sev_supported ? "enabled" : "disabled", + sev_supported ? min_sev_asid <= max_sev_asid ? "enabled" : + "unusable" : + "disabled", min_sev_asid, max_sev_asid); if (boot_cpu_has(X86_FEATURE_SEV_ES)) pr_info("SEV-ES %s (ASIDs %u - %u)\n", From patchwork Wed Jan 31 23:56:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 195087 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp100801dyc; Wed, 31 Jan 2024 15:58:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/KSnBCeoJe2P5C4j0cBYSf0RlZy7uAk9/UgxQ8vUkafPK+VJncMZ+yTvqIkYfYdzdKSmh X-Received: by 2002:a05:6402:c10:b0:55f:aed2:1c49 with SMTP id co16-20020a0564020c1000b0055faed21c49mr255494edb.21.1706745502991; Wed, 31 Jan 2024 15:58:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706745502; cv=pass; d=google.com; s=arc-20160816; b=mA2Vw8ehvrWUJmor/c++9Nm9CX8SBUd2LleMpgyTgbtx3/1w0cJ+0RL5tFHgIw5W+B IGqgaMR9Tqw1NxZ8kZv0Mv5YvR6oKg3dwdjUVJmvh6jxAjtxHDceEpn2H/2MLeTLp+LK yFoJwTUSSQNAq1KLvLYmmILGnDnCGv3PkV469u4V9KdbZ42BXysGveWCExtyiNKebNk3 CM5Y7gHljzMu3xNYOw0+gds1CeySLo+sx4JDCffbfWOJhgYBwaue/93RLk366QbAslj+ ju7iPxB3BoQ6uohA2UZSN/GAMSQUtk9Hnkwvj5lq2b3CRmABN+2b9JrDMeoQfzUYSXMH bFdA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=yNChpOdBDlQ0ccn6PmbEc8ewiIrWgLKikwCTAZH7kF8=; fh=MvJiXdvYe6MQ8FgXyMu+AlP/UASyk3qIdFdQzGcEVJA=; b=FM2sKhHo3nYM5deppPJlqFPhP6XEPZZMp6DRK4SDrlQuNzlYnsLRyF6yKlGW30zTWu Zr+OewbYipZJgF9cpyZorIjbEUEvKlNvbFNzGUQOh7ciQzwQnTdvOT/c9bt0SLmGLCde E7ayTSl7MxtAuX6e0mZQDx97D5ubUfBcM/bWWM6/lTLPDDcj7h0cTjxe6dmNEsiW3YpA ycqGR7jCkbJlY23CJQojc6wRIAflCuM1qUKuaixQ/rqI6Re6o4sqpSE7m6gt1WwiWG2L Dlo0CQrxdldxPi7Kn/HLNSaYEwq6Mq1cG+Yz3QIU72SNTAFMa4/hJ1sATonqSxaS66o/ UFaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jCj4pBkI; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47403-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47403-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCVfNCQQQ+fy3WWbEm0XqfoQ8H+o0iT16ECHqBjvNBPLz6FZjw7Qw7qQzdQk80TBwLIdBuEU0kdTuVLOSlOaA18ve8KFKw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bl17-20020a056402211100b0055f3d5e1c90si2490886edb.489.2024.01.31.15.58.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 15:58:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47403-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jCj4pBkI; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47403-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47403-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9A7FC1F25C05 for ; Wed, 31 Jan 2024 23:58:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4859A405DF; Wed, 31 Jan 2024 23:56:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jCj4pBkI" Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3772C3D0A3 for ; Wed, 31 Jan 2024 23:56:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706745381; cv=none; b=mjKQ8fRnw3l00MzK1XDaeznLmAB33jSSesWJogSQqwyFeXEZ1yLeyfEpcdR4YOMTV9gvs08yeYY5dK1kZqAH+KmhAMBdUe7Dn5Qd/yV1zvWIoyQg3RyX2x7c2AhsI7Yv3ycramz0+W7WWVYiOYUHrvgN8yUbBYd1Jd7BY0LClbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706745381; c=relaxed/simple; bh=dJzDRHZ4lvHqnCEXSzwyrLR5DGIflpjXQoxReg/o7XY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gNIDZeO7ZRETGoXlrmbC+Nx9LEVR4rr+5noUnNZsnjge4dwKd3aiTU5UkDj+wUUPS8DGtjAQOSsTylkwW07wtdPqXVQpZVFHYrE/CuKydLO5yqN0eHcFIHQPxhb9f+Fz6GxREszEhR9vFUaIzjnr6y4TrtiSPRJyBZcovkP/GfU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jCj4pBkI; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-5cf2714e392so232044a12.0 for ; Wed, 31 Jan 2024 15:56:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706745379; x=1707350179; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=yNChpOdBDlQ0ccn6PmbEc8ewiIrWgLKikwCTAZH7kF8=; b=jCj4pBkI9HgR+IeJsNF9dobIM76elCbTIgKk4h/ayPUdl0+FYpXwmVuUfJ5PzF8A8J CBoHx5a/kZTBxoVcnqcGg/G8QDOjsMQcpwPo0grIF5KUG0GjPbTgF29R6NIQbBcnKX7H LEK31rmIqNscZOrex+6NzOcgs+Eidca+ZTFRHdEuFaU+9uwsi7hIAUia2cUHr1R7+myb gEHeAQ+s9SpIiDoLRI3NBUHKMJ7Q8oD1JB1c5ju0jA2irn2jmzz3FFv4HOTvX5TRju01 L68CkRgBJel/SnhCVkJ/MQoyoTkzxnrX/4zwgusRuArJB3Nnpigr5ZttMDLSlcE/mE19 oDWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706745379; x=1707350179; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yNChpOdBDlQ0ccn6PmbEc8ewiIrWgLKikwCTAZH7kF8=; b=uf3MR4ytf+nmyk6TWHcCeiP+uALFPS30R9R6/dqMDh+eJTLNOhxYo5M2f9kIzka7Ig dF+QZEeIKDKalYvVU1B9XnBwRAgJyLNbHvdUAtQ3UdLjiiW07RYjyjatIgpKYk1UD+H7 gSNH4zLqvufB1XvRYdPTg6qQie5lqeiG6UoBlQkLLMJtRerJZlpzoPHpkQryvYxzoVhF 3wBwocI/Ud07Im8/htyDDvFG3xh0qOqnN4iKZtNpr2jVy3iJQrJ3OwbKSf36rrxjOnAv zjt1ENoARo+mMyHU7muxW+CJ9/cmWGlJPP3gu4waSKfVDboCum5qHs681x10UsM73Gpi RvOg== X-Gm-Message-State: AOJu0Yzp4c2pstcSO7ZNUhSeVLz5o/1wWn0Mb+Cis0OOU+6pQ9PayHfW zwwcZCryONyKpntH8PzTC2C+3DZDTUIg9tNQThJgom1vM8r3VFAGK2P4PCnDe1wXQ05jN5xwgah 4uA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:8849:0:b0:5cd:c9af:ff21 with SMTP id l70-20020a638849000000b005cdc9afff21mr191194pgd.3.1706745379511; Wed, 31 Jan 2024 15:56:19 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 31 Jan 2024 15:56:09 -0800 In-Reply-To: <20240131235609.4161407-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240131235609.4161407-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240131235609.4161407-5-seanjc@google.com> Subject: [PATCH v4 4/4] KVM: SVM: Return -EINVAL instead of -EBUSY on attempt to re-init SEV/SEV-ES From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ashish Kalra , Tom Lendacky X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789652372708158318 X-GMAIL-MSGID: 1789652372708158318 Return -EINVAL instead of -EBUSY if userspace attempts KVM_SEV{,ES}_INIT on a VM that already has SEV active. Returning -EBUSY is nonsencial as it's impossible to deactivate SEV without destroying the VM, i.e. the VM isn't "busy" in any sane sense of the word, and the odds of any userspace wanting exactly -EBUSY on a userspace bug are minuscule. Signed-off-by: Sean Christopherson Reviewed-by: Tom Lendacky --- arch/x86/kvm/svm/sev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 38e40fbc7ea0..cb19b57e1031 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -259,9 +259,8 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) if (kvm->created_vcpus) return -EINVAL; - ret = -EBUSY; if (unlikely(sev->active)) - return ret; + return -EINVAL; sev->active = true; sev->es_active = argp->id == KVM_SEV_ES_INIT;