Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp519057lqb; Wed, 17 Apr 2024 03:30:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXkHhShjZEHLW7g9hk55WxxZAThWCyipoKOmBDs5iBq0SccoY7+dJCPqNoB53FVEaqrP7tCmGfp/MrSpSASpxZvcnDGJwMAKcEUn8k2FQ== X-Google-Smtp-Source: AGHT+IFQquafGzEb9uyqwX+z2+P60Y27sJVX5NdHZNzKiItITtwuSzanORS4xXUdnzuZpBb6SHNT X-Received: by 2002:a05:6a00:13a0:b0:6ec:da6c:fc2d with SMTP id t32-20020a056a0013a000b006ecda6cfc2dmr18262328pfg.23.1713349815902; Wed, 17 Apr 2024 03:30:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713349815; cv=pass; d=google.com; s=arc-20160816; b=Ljyv6cs/4yX4qJFiNln5BB+DwOjY4T47UYlCyxXVjRfPhxi2BUqJFllXx5JIZBYvbb 6Vm/d4D36fQrkjM+IdQxE+Q4w6zfFVdZ39cgb8oNPs/SWaRyKGuZrI4zkm6rgmrTBXx8 z3vT8lwvJVfY5XKN/vKLvq2aJnhw/hBsKF5UE1BoSU2JdpMXZksp3yJKbrfOYtOILmuT atQE4Ccf9r8J48fI1m/P2uuOjUi1wzFKG8SAw2e/peYggAtAS0AyL+ABBIwNKI5swl/A YeL1+k5ozmS3EZ5DgXhHR1uL7ZD+wIqqw427AwMUKz5XpfSkRXvm1XWPNcx2j5IFWy/P M65A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=O85bb4GMOKWlSLPww3MfE2bfVcvNnZa2l+DfV3fmaMQ=; fh=Re94RtPatehaHi0UVBKvk8JuT570TNfaQLlbzzZ88uw=; b=hDKJ8l/98Ew/xPpDoIRL3WD0JffASMxY9IlDL9n/+H94lF7hszsnAALvjKR16WPu6R ypGUpgh/GNfsbxdtLcjZjN6Pfhvc6Le97enrXRH5PXyUBBcmovA9qy/3tEvLZCMJfsN/ NAgzD8pyGOota0ASlCIpv+3Piw+O0uu8A/tbp4FOa482y+byJQIMtsTGAx1MfY4fiIk4 ZHI5tcS6S1KCMKww4TQXPTKpyjgPKr43MHSE8SKsTuw12JLSy++4d3BARDK1GcxcTezk hw/D0Wb0q5C/D86907iwl3LegEtJKpFslXJmhtGgPq6hN99/tBzuSJuLTCK3MBaNYtDw xBwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XvtIceW5; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-148322-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148322-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id ca8-20020a056a02068800b005d8e379746asi4495391pgb.630.2024.04.17.03.30.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 03:30:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-148322-linux.lists.archive=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=@redhat.com header.s=mimecast20190719 header.b=XvtIceW5; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-148322-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148322-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 5CF4CB21562 for ; Wed, 17 Apr 2024 10:29:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA8AB13BC26; Wed, 17 Apr 2024 10:28:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XvtIceW5" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BC3412CD91 for ; Wed, 17 Apr 2024 10:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713349732; cv=none; b=kQeq4cijLqA9lIZZkPDH+wDR3GlaOEwiJ+TnWP5igk2sL6a9XxsWizHwaAR666mzgXtfrnhEePDqNW/Het7QRT2Vc4viKLBG3VYIS+IgFwbzd52pb2qAMsSKBn4DDMxhQr5toZ06pyPXL4oNUleLCjc9/OMDCi30LW6Gl4jbM4c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713349732; c=relaxed/simple; bh=w9/j/Je+o73zYIJxkI4ihGGFo9ICotiVF5tQW2c+m+Y=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=rTB0dL8Yy+DD5fP4Cj+DQFKwrzsRGhPi5ABBnnXDiIhXMrGJKYCqevjJSQzEkUad/Bww9lCGIXlgEqRfEOHeESgH4hofLonuPhM4TgI6AztRFtnqJwfEbpQYWJnhKYLL41HyMnbm976Rjlm9VXP8tIR/T+wc0jYjrDVUmVqHwIM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XvtIceW5; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713349730; h=from:from: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; bh=O85bb4GMOKWlSLPww3MfE2bfVcvNnZa2l+DfV3fmaMQ=; b=XvtIceW5MDN6miq6TFePW75qwYPdMhUILhK5MUGqFdFPH8irdijgHrEk6nLtEJC/Cz7vAS Vhgew8Pos10dYNy3X8e8Rd7jJvuSEv1ssQ+BBDWaI8h/Ahow8jPm3+Q1PiYoyFAPYC2PJA s/iNlPhUxfZ/EfhwKKRkDVhyOSmcVew= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-372-WjCGFWYDNautd4ZFFrW29g-1; Wed, 17 Apr 2024 06:28:48 -0400 X-MC-Unique: WjCGFWYDNautd4ZFFrW29g-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-519296de7cfso1371554e87.3 for ; Wed, 17 Apr 2024 03:28:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713349727; x=1713954527; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O85bb4GMOKWlSLPww3MfE2bfVcvNnZa2l+DfV3fmaMQ=; b=vHIkh75a416jeslJGW3HZqfTiEioH+ZdAuSNmPWKXJtjhFBbaJtEv6jMe7GTEV6+Qw ptwr7ezbLKVxFJweXQVJqICmpaeKc60y/g60DPqnShV6VZr1O7vGWFYTMNUuxjCNlQVu NjFpNcXwrzawbo7rkMwJOHRXlxHdChHLjy5AakAcz/AOrkfZ9zkjJur50K5x7BL7vDs3 DdjcDIrc6SqA5PugJaFOMWiBNu0K5pKXA+9USPgvYDuI7D0hkTCeKyCaZwmUFTPryS/Y /pDGm6nZ8u5HsFznMs9NuXwsiGP3rLD1iXKcOnqRAJKqHppBrdxht9D0WXb775XCXirR n5Jw== X-Forwarded-Encrypted: i=1; AJvYcCXHPYr5+zadGMG2O7hgbKUQs27bYmOWewKahPvjoBy84da29rrL7iJhrHSHwpIY3ysHyZ5q7iedPnLYWP3OncU79boId8/64LqbtFPu X-Gm-Message-State: AOJu0YyJglhZZBTRTEDSVa2g5RUInLKzrTTQackdGRWol3/m5lLN5ulk CwvWJ3Xggfj1CrD+PHnSydKqqAL4jxCukNIL+BmhWIpdzPjErjr4TckWuTcCIn72LIU82ERoUa2 1usPfqyeuxQnsT7BD0/HuEwNGhHnSBTIBVN3t6EQJ8wXq6lb5vRcmAlQBa2ux1OgRMPvWOpEhCA ItnkZsoHGg20ecOEaw2xNRgTjKCGhZCbrhbwNS X-Received: by 2002:a05:6512:ad5:b0:515:ab7f:b13e with SMTP id n21-20020a0565120ad500b00515ab7fb13emr15605110lfu.33.1713349727155; Wed, 17 Apr 2024 03:28:47 -0700 (PDT) X-Received: by 2002:a05:6512:ad5:b0:515:ab7f:b13e with SMTP id n21-20020a0565120ad500b00515ab7fb13emr15605089lfu.33.1713349726809; Wed, 17 Apr 2024 03:28:46 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <2f1de1b7b6512280fae4ac05e77ced80a585971b.1712785629.git.isaku.yamahata@intel.com> <116179545fafbf39ed01e1f0f5ac76e0467fc09a.camel@intel.com> In-Reply-To: From: Paolo Bonzini Date: Wed, 17 Apr 2024 12:28:34 +0200 Message-ID: Subject: Re: [PATCH v2 07/10] KVM: x86: Always populate L1 GPA for KVM_MAP_MEMORY To: Sean Christopherson Cc: Rick P Edgecombe , "kvm@vger.kernel.org" , Isaku Yamahata , Kai Huang , "federico.parola@polito.it" , "linux-kernel@vger.kernel.org" , "isaku.yamahata@gmail.com" , "dmatlack@google.com" , "michael.roth@amd.com" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Apr 17, 2024 at 1:00=E2=80=AFAM Sean Christopherson wrote: > > > > Hmm... For the non-TDX use cases this is just an optimization, righ= t? For TDX > > > > there shouldn't be an issue. If so, maybe this last one is not so h= orrible. > > > > It doesn't even have to be ABI that it gives an error. As you say, > > this ioctl can just be advisory only for !confidential machines. Even > > if it were implemented, the shadow MMU can drop roots at any moment > > Sure, but there's a difference between KVM _potentially_ dropping roots a= nd > guaranteed failure because userspace is trying to do something that's uns= upported. > But I think this is a non-issue, because it should really just be as simp= le as: > > if (!mmu->pre_map_memory) > return -EOPNOTSUPP; > > Hmm, or probably this to avoid adding an MMU hook for a single MMU flavor= : > > if (!tdp_mmu_enabled || !mmu->root_role.direct) > return -EOPNOTSUPP; > > > and/or kill the mapping via the shrinker. > > Ugh, we really need to kill that code. Ok, so let's add a KVM_CHECK_EXTENSION so that people can check if it's supported. > > That said, I can't fully shake the feeling that this ioctl should be > > an error for !TDX and that TDX_INIT_MEM_REGION wasn't that bad. The > > implementation was ugly but the API was fine. > > Hmm, but IMO the implementation was ugly in no small part because of the = contraints > put on KVM by the API. Mapping S-EPT *and* doing TDH.MEM.PAGE.ADD in the= same > ioctl() forced KVM to operate on vcpu0, and necessitated shoving temporar= y data > into a per-VM structure in order to get the source contents into TDH.MEM.= PAGE.ADD. That's because it was trying to do two things with a single loop. It's not needed - and in fact KVM_CAP_MEMORY_MAPPING forces userspace to do it in two passes. > And stating the obvious, TDX_INIT_MEM_REGION also doesn't allow pre-mappi= ng memory, > which is generally useful, and can be especially beneficial for confident= ial VMs > (and TDX in particular) due to the added cost of a page fault VM-Exit. > > I'm not dead set on this generic ioctl(), but unless it ends up being a t= rain wreck > for userspace, I think it will allow for cleaner and more reusable code i= n KVM. Yes, this ioctl() can stay. Forcing it before adding memory to TDX is ugly, but it's not a blocker. I'll look at it closely and see how far it is from being committable to kvm-coco-queue. Paolo