From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAB5AC61DA4 for ; Tue, 14 Feb 2023 18:07:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233297AbjBNSHu (ORCPT ); Tue, 14 Feb 2023 13:07:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233281AbjBNSHs (ORCPT ); Tue, 14 Feb 2023 13:07:48 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 780FD2FCED for ; Tue, 14 Feb 2023 10:07:30 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-4bdeb1bbeafso166371317b3.4 for ; Tue, 14 Feb 2023 10:07:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=wX05IVkHj3QBCA1mIon81shk3MJEJQ/4hz193u4oHCc=; b=Dt+QCXEL/j2OVlYZG+8qwoo88m8d8gSqPp1DJoQ+IGJpPuoZGZ7SYYDdYB8+yJ3eDl jeP6IZHDHerpXSU/A3lwaLOqhRFKoFsgEci4P2KArqSNVmooBA2C7+kM9EYWXXJTyLae Xg1dZ+EziJ8yGcFploTgi9FMPrPslHsMYXReHQVo9CBAaIj0P6zc7wVMCM6iWLSQwSfv rIpX9OdI9ocknhGSMghX+77PCRzZY4cpQYWxW05GrdrgU5xkG+PmVmF6RvgPoyIDvsRh kG8ONtGxcufDvuzLkSW/HaWjLqmZO3eUfiS87W6x7qkvY49eByyFST1j571DlgUotIiS /nZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wX05IVkHj3QBCA1mIon81shk3MJEJQ/4hz193u4oHCc=; b=O3xm7SN7rzRur5ow5iqwc8FmJvUjYfmaThJZxc9LPrhh6/Uo45w7FiIr7TKjm3yNEm 710Lcedeu4C7wLnQKtXrAfrUTqhxY8GH6P6mYhHsPZSN0dt8d+HtAbwglagEOdUbQWhw 9ZG0WUyN6+nTmLqgljOdlmAq/pQ71p33vNAXS9V2ZJ5AjAx2D7C6NnVoizzMQiYVrnEw CVZEK8ck6Kk/jT93gBU3wd7UVZmXGAwluy0csp6Ucchto987ZP+UjbpgGxA8hBkdMcf9 tU1IglgTtJG/55XlVCuHfbAWdLtx0QPJcfhWs7k20f90yiU6TeIRJtxFiojT5bVZgY0W quZw== X-Gm-Message-State: AO0yUKUaf5/gHVacvAJ+uNYKNTrFBvlXlvxMJ2A/HcpgSeFuEQ0lPYiI bMv7+sfy5li8AwG3mykfGdqa6ChKAm4= X-Google-Smtp-Source: AK7set+EI7pNBbm5Gukj5zYQbLZVnpf4V0D4zMPyPaLWe/aBZALXoW94wxCwwjPKImE/Ubi3qEmpRmHjMf0= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:dd0a:0:b0:52a:9490:4f66 with SMTP id e10-20020a81dd0a000000b0052a94904f66mr350779ywn.56.1676398049608; Tue, 14 Feb 2023 10:07:29 -0800 (PST) Date: Tue, 14 Feb 2023 10:07:28 -0800 In-Reply-To: <20230213235343.GC4175971@ls.amr.corp.intel.com> Mime-Version: 1.0 References: <20221202061347.1070246-1-chao.p.peng@linux.intel.com> <20221202061347.1070246-3-chao.p.peng@linux.intel.com> <20230209072529.GB4175971@ls.amr.corp.intel.com> <20230213235343.GC4175971@ls.amr.corp.intel.com> Message-ID: Subject: Re: [PATCH v10 2/9] KVM: Introduce per-page memory attributes From: Sean Christopherson To: Isaku Yamahata Cc: Chao Peng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Arnd Bergmann , Naoya Horiguchi , Miaohe Lin , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Shuah Khan , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , tabba@google.com, Michael Roth , mhocko@suse.com, wei.w.wang@intel.com Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Mon, Feb 13, 2023, Isaku Yamahata wrote: > On Fri, Feb 10, 2023 at 12:35:30AM +0000, > Sean Christopherson wrote: > > > On Wed, Feb 08, 2023, Isaku Yamahata wrote: > > > On Fri, Dec 02, 2022 at 02:13:40PM +0800, > > > Chao Peng wrote: > > > > > > > +static int kvm_vm_ioctl_set_mem_attributes(struct kvm *kvm, > > > > + struct kvm_memory_attributes *attrs) > > > > +{ > > > > + gfn_t start, end; > > > > + unsigned long i; > > > > + void *entry; > > > > + u64 supported_attrs = kvm_supported_mem_attributes(kvm); > > > > + > > > > + /* flags is currently not used. */ > > > > + if (attrs->flags) > > > > + return -EINVAL; > > > > + if (attrs->attributes & ~supported_attrs) > > > > + return -EINVAL; > > > > + if (attrs->size == 0 || attrs->address + attrs->size < attrs->address) > > > > + return -EINVAL; > > > > + if (!PAGE_ALIGNED(attrs->address) || !PAGE_ALIGNED(attrs->size)) > > > > + return -EINVAL; > > > > + > > > > + start = attrs->address >> PAGE_SHIFT; > > > > + end = (attrs->address + attrs->size - 1 + PAGE_SIZE) >> PAGE_SHIFT; > > > > + > > > > + entry = attrs->attributes ? xa_mk_value(attrs->attributes) : NULL; > > > > + > > > > + mutex_lock(&kvm->lock); > > > > + for (i = start; i < end; i++) > > > > + if (xa_err(xa_store(&kvm->mem_attr_array, i, entry, > > > > + GFP_KERNEL_ACCOUNT))) > > > > + break; > > > > + mutex_unlock(&kvm->lock); > > > > + > > > > + attrs->address = i << PAGE_SHIFT; > > > > + attrs->size = (end - i) << PAGE_SHIFT; > > > > + > > > > + return 0; > > > > +} > > > > +#endif /* CONFIG_HAVE_KVM_MEMORY_ATTRIBUTES */ > > > > + > > > > > > If memslot isn't private, it should return error if private attribute is set. > > > > Why? I'd rather keep the two things separate. If we enforce this sort of thing > > at KVM_SET_MEMORY_ATTRIBUTES, then we also have to enforce it at > > KVM_SET_USER_MEMORY_REGION. > > For device assignment via shared GPA, non-private memory slot needs to be > allowed. That doesn't say anything about why setting attributes needs to poke into the memslot. The page fault path already kicks out to userspace if there's a discrepancy between the attributes and the memslot, why is that insufficient?