Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3944806rdb; Thu, 14 Sep 2023 07:27:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3H/S0nKbg53OZXXrgNnPoFomoVehXXa8W9DXdZGWshmMJ6oBXvHWVrZJaP3pvCiinLH6D X-Received: by 2002:a05:6a21:4994:b0:14c:4e31:97f3 with SMTP id ax20-20020a056a21499400b0014c4e3197f3mr4969463pzc.59.1694701667233; Thu, 14 Sep 2023 07:27:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694701667; cv=none; d=google.com; s=arc-20160816; b=BAquLySsW0uhtnKMpG/CvwuLYFxbELa8PYFMltByFb7ikfqxdU04lm/eE6T5Qe35+U i7ajPbtXIlWVzCqvaDpFe7L/X9B2HG8gZhySvCKXLpLlLVCA+GwABWmzP3QWfc+ezl4z LqYfCnCDsG/RPPUZBKZAByQVNbfPiTg0nZS3QHvp9o8jdY+N7XqQSwXhuZfxh6/NK4YJ Bpd8gVF0b+/cYbSHKXgFymShylYxhPrIbnObfKb7kMhmpRqncsDEseLUKNfylbHwfIJL SRbw/WgfwgQH/q33/DWSwxkBE5bx3WHkzUTOsulSyDt3/osg/a5msIShzNm3oSYoyF5j 3Btw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=/ocbK288Al1DpwUeolIoLVHrflqgxdyru7h8mWey0wo=; fh=4zSMCzNb7rJrUGZtbNPceVM+tszI9ngqwF5WBZpI8NM=; b=zOgumS/6j7ZubI3w7nIQMo0D8frS4KySIWvzq1WRV+L0y/UokYN3HvAA90+ZaYl+QF 9pyGY4SpvZnJMIPHzFesRApo7jwdQ/Ap7YVdyA8vslVbXY9r2P8/8G6nucQ9hmTKmz0H SIjnJcY9VZmwWBPvloTqjZvYhv7mxLVRF6AbC6owYJ/QDFsdvCuVVus8YRxoZ0wCg3rV BM8S9dm9Zi/nQNqv9vno0YJ/XzsyHMMRt0wf+xSEZuNnO8v9C5VtjmAQXEIL0KhnnkR0 RAz1IgSRKpJzvJAeTzHQDwlATUeiiEDyGnWLnx7A0a5R8ynASOmXodB+UoC7duhBe2w4 IrVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bRX+fw1+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id 14-20020a63184e000000b005655e87c8aasi1547915pgy.192.2023.09.14.07.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 07:27:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bRX+fw1+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 44645822CEED; Wed, 13 Sep 2023 10:46:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231370AbjIMRqU (ORCPT + 99 others); Wed, 13 Sep 2023 13:46:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231531AbjIMRqR (ORCPT ); Wed, 13 Sep 2023 13:46:17 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6581219AC for ; Wed, 13 Sep 2023 10:46:13 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d81841ef79bso113372276.1 for ; Wed, 13 Sep 2023 10:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694627172; x=1695231972; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/ocbK288Al1DpwUeolIoLVHrflqgxdyru7h8mWey0wo=; b=bRX+fw1+7a8iLbidTBYkBFr230SoMZaQINwo5EkmKFYmLyz9FO0777ON+9CDsoGgrP RaIqSQ2eWPwWpntXBcu+yu6b6IDeZBcDQy76lEtrZOqoVYHIByG2RM18r0FkRlb0CsP1 t6uY/IL3he/h3anC+mQ/mBRJcfSJsFqXYbnGzHhnz8T+kFeBxbbqw8iTj/2EpoULBWSi 8rnbNQVjIejAYZNqTB4vhu9dmBzMVho3SkfEyZv0DYFIkFn6dxjx806hFB+K9XeNTHJy a0gEN8EwkaivFPpkJcw+0ZzIxaXZM18f4G9XxABHYxy84fFWU7whDgIWALFZwAQfyMl/ LOZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694627172; x=1695231972; 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=/ocbK288Al1DpwUeolIoLVHrflqgxdyru7h8mWey0wo=; b=fzc9yiCtq5F76h0smbG9SAy29/V+hTKWtHgOMslbJWyEqEd3erwj3gQTTjItTpNVpw 6AlwqznfwlvmGEBUPVxqrWH8+sQcVeX3ezpNhujt4JfhEl+cXiCEV0VXSWF3Or7xVexf wHQqJR1edfcgPjbkQsnONWF/PfsWw2jGXUlaArcmOg9TJH4QgLZO+20UCCmL/ZxOOY9J Ouv9QxRkD/MzCXMHXIRbcwgq0479N/UT/vGlkw8+MowRn0/kV0+tH+1UWrvFloi450tb trFB9fxGX9UxNWygJvnnAKHiYU8rp8qCpYpqymc34os6Dgo4JcPfLOqJI/4I6IJfviiD HAqw== X-Gm-Message-State: AOJu0YxQaHeSVsE93CES+DM21bH3huiCIz2/LUsP8NzQ/1JEP8BNixCY 5l2xqzSOeRqNfMCrKLK/CvrzFuh/Zcs= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1102:b0:d0b:d8cd:e661 with SMTP id o2-20020a056902110200b00d0bd8cde661mr95997ybu.12.1694627172692; Wed, 13 Sep 2023 10:46:12 -0700 (PDT) Date: Wed, 13 Sep 2023 10:46:11 -0700 In-Reply-To: <852b6fa117bf3767a99353d908bc566a5dd9c61a.1694599703.git.isaku.yamahata@intel.com> Mime-Version: 1.0 References: <852b6fa117bf3767a99353d908bc566a5dd9c61a.1694599703.git.isaku.yamahata@intel.com> Message-ID: Subject: Re: [RFC PATCH 4/6] KVM: guest_memfd: Implemnet bmap inode operation From: Sean Christopherson To: isaku.yamahata@intel.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Michael Roth , Paolo Bonzini , erdemaktas@google.com, Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, linux-coco@lists.linux.dev, Chao Peng , Ackerley Tng , Vishal Annapurve , Yuan Yao , Jarkko Sakkinen , Xu Yilun , Quentin Perret , wei.w.wang@intel.com, Fuad Tabba Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 13 Sep 2023 10:46:46 -0700 (PDT) On Wed, Sep 13, 2023, isaku.yamahata@intel.com wrote: > From: Isaku Yamahata > > To inject memory failure, physical address of the page is needed. > Implement bmap() method to convert the file offset into physical address. > > Signed-off-by: Isaku Yamahata > --- > virt/kvm/Kconfig | 4 ++++ > virt/kvm/guest_mem.c | 28 ++++++++++++++++++++++++++++ > 2 files changed, 32 insertions(+) > > diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig > index 624df45baff0..eb008f0e7cc3 100644 > --- a/virt/kvm/Kconfig > +++ b/virt/kvm/Kconfig > @@ -115,3 +115,7 @@ config KVM_GENERIC_PRIVATE_MEM > > config HAVE_GENERIC_PRIVATE_MEM_HANDLE_ERROR > bool > + > +config KVM_GENERIC_PRIVATE_MEM_BMAP > + depends on KVM_GENERIC_PRIVATE_MEM > + bool > diff --git a/virt/kvm/guest_mem.c b/virt/kvm/guest_mem.c > index 3678287d7c9d..90dfdfab1f8c 100644 > --- a/virt/kvm/guest_mem.c > +++ b/virt/kvm/guest_mem.c > @@ -355,12 +355,40 @@ static int kvm_gmem_error_page(struct address_space *mapping, struct page *page) > return MF_DELAYED; > } > > +#ifdef CONFIG_KVM_GENERIC_PRIVATE_MEM_BMAP > +static sector_t kvm_gmem_bmap(struct address_space *mapping, sector_t block) > +{ > + struct folio *folio; > + sector_t pfn = 0; > + > + filemap_invalidate_lock_shared(mapping); > + > + if (block << PAGE_SHIFT > i_size_read(mapping->host)) > + goto out; > + > + folio = filemap_get_folio(mapping, block); > + if (IS_ERR_OR_NULL(folio)) > + goto out; > + > + pfn = folio_pfn(folio) + (block - folio->index); > + folio_put(folio); > + > +out: > + filemap_invalidate_unlock_shared(mapping); > + return pfn; IIUC, hijacking bmap() is a gigantic hack to propagate a host pfn to userspace without adding a new ioctl() or syscall. If we want to support target injection, I would much, much rather add a KVM ioctl(), e.g. to let userspace inject errors for a gfn. Returning a pfn for something that AFAICT has nothing to do with pfns is gross, e.g. the whole "0 is the error code" thing is technically wrong because '0' is a perfectly valid pfn. My vote is to drop this and not extend the injection information for the initial merge, i.e. rely on point testing to verify kvm_gmem_error_page(), and defer adding uAPI to let selftests inject errors. > + > +} > +#endif > + > static const struct address_space_operations kvm_gmem_aops = { > .dirty_folio = noop_dirty_folio, > #ifdef CONFIG_MIGRATION > .migrate_folio = kvm_gmem_migrate_folio, > #endif > .error_remove_page = kvm_gmem_error_page, > +#ifdef CONFIG_KVM_GENERIC_PRIVATE_MEM_BMAP > + .bmap = kvm_gmem_bmap, > +#endif > }; > > static int kvm_gmem_getattr(struct mnt_idmap *idmap, > -- > 2.25.1 >