Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1045269iob; Fri, 13 May 2022 20:55:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVyF6ziMGz815ZxNuJEQo43bjtNxAPPDrIOhnP+zgqIRM6QICmyeFe6C9yyxyH+AkCU3IV X-Received: by 2002:adf:e2c9:0:b0:20c:dbc2:a411 with SMTP id d9-20020adfe2c9000000b0020cdbc2a411mr6102398wrj.391.1652500502548; Fri, 13 May 2022 20:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652500502; cv=none; d=google.com; s=arc-20160816; b=aItnbd1P/EugXtHcpr2++2Ih0SgchecErq53B8l/pPZJdhiyz38ENaGI0QKxqWJr4s BlvHfvkuiHUaG21nEYslJk0R08POztQCJntptLBxejTxyW2lvL+vMu75b1Lw5fFPWtvO wYMPDrmY5sYc54Fi9QmbGvr3Vt+QtrTCr83k2YR0ObCDpfPMJ+guQNewRQRFnZkVUJS0 UC0AM22UxQ3/5v3g8VO3zqG7nFijdrYn1fzge2TBYw0/WMgYDLe19Rz2oadQbqjcKYl5 xTwv/Jq+VmasCq3mAu0t7GBdttBQF8SOmIJu0GHW1fiYzAG5u3ch9O2hQo6OhvlT8lQD 1wtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=Ir1zw0OZe5UU2KiBzSYOwuHmCrXrkYEC7RGqZNVaeEM=; b=nr5bxo0npo9DlyXEWlYs4Lls2fmQa5FP+bIRUBfYgaCjXDUJr5jKKF+OoEA+ErOfaI 9awovQ2UMvJiqYnIojbk+1sgwyDSZFCvfUyw35zi2BPsVQDbCx3UtZa7YIe8e6KRckyj eyerpRJbJ3VeNmY2tDbtHm0+qYjP24OuFS28gSiqyoM08BDD1vZGpECNUv5UXMEb5pzg Tn/OGmETM68gR8fjlC+qHQQdS8p6QBtAHityq5Byu8ImCgCxnf5Eo+OZs3A+DkCrSktv WyhDQMTpFFiZYz1Sb00kl9Uvg1rHH8ILHqaoR4WhNRC1nwGscQATEZUF6nTZqIKxIMzN SMtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b="IvE6/JS9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p17-20020adf9d91000000b0020cdff2f70asi3499672wre.847.2022.05.13.20.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 20:55:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b="IvE6/JS9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1AEE02F6261; Fri, 13 May 2022 17:27:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357186AbiELRlN (ORCPT + 99 others); Thu, 12 May 2022 13:41:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357201AbiELRlC (ORCPT ); Thu, 12 May 2022 13:41:02 -0400 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6273537A90 for ; Thu, 12 May 2022 10:41:00 -0700 (PDT) Received: by mail-il1-x131.google.com with SMTP id h11so4051325ila.5 for ; Thu, 12 May 2022 10:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Ir1zw0OZe5UU2KiBzSYOwuHmCrXrkYEC7RGqZNVaeEM=; b=IvE6/JS9OoyiNcMDOiJ6ONy7E+AnfyES5kY3vljwcFFCH5EJ2w4OWI0JhOekQErXdD jV+1Rw5uvDB61t4c1HIlfmHGaZKUKuG/KQbyC3kVZ3bAjrq/5ZCPz/4kVyLIszDiFvwX 7ym2TWAqgaTUCfGwgC/P+uk4t8jRoUwtK3Yfg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Ir1zw0OZe5UU2KiBzSYOwuHmCrXrkYEC7RGqZNVaeEM=; b=fM2j76k5qxKsTFy0SdvbuVG/ZRqqdd4n7pgKDDVI5bLmsxN+xq3HUIJPerfacd5jwl unhNop9kkq05VZJ3cxLvaB31Qq/plHbnWlNhtP4bOeOg6mWMP1M0M8mMoSxm2T7PgcIj b86PXGYtIieu2MIKDShBCRzMd5egyxDENT4XshNzdkd8QGTiwfYUbgcTnJ58mCrO/zXG GNIhDSe2hguf6oh25dYgyXQvDP+GxOJtCqOi9U9WGXNR4EH7AXoaC0BzsmTc+tgmctky r6OXY01+bckilmXXu1D7fHz1ldi1DW9xOYyWR1zsB11rvL79FhuIYlWukTMhCbaxBkUt 7iyg== X-Gm-Message-State: AOAM530qw/HBHDXRloYJVbyUfVXkTZ/b/FZouiKFyaQJlLz9rGVFAbDU Lqp2fru3z1VznfMjP13fk8/TiA== X-Received: by 2002:a92:6e0b:0:b0:2c9:a276:58cc with SMTP id j11-20020a926e0b000000b002c9a27658ccmr576228ilc.199.1652377259680; Thu, 12 May 2022 10:40:59 -0700 (PDT) Received: from [192.168.1.128] ([38.15.45.1]) by smtp.gmail.com with ESMTPSA id i3-20020a02ca03000000b0032bf978122asm41450jak.59.2022.05.12.10.40.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 May 2022 10:40:59 -0700 (PDT) Subject: Re: [RFC V2 PATCH 3/8] selftests: kvm: priv_memfd_test: Add support for memory conversion To: Vishal Annapurve , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, shauh@kernel.org, yang.zhong@intel.com, drjones@redhat.com, ricarkol@google.com, aaronlewis@google.com, wei.w.wang@intel.com, kirill.shutemov@linux.intel.com, corbet@lwn.net, hughd@google.com, jlayton@kernel.org, bfields@fieldses.org, akpm@linux-foundation.org, chao.p.peng@linux.intel.com, yu.c.zhang@linux.intel.com, jun.nakajima@intel.com, dave.hansen@intel.com, michael.roth@amd.com, qperret@google.com, steven.price@arm.com, ak@linux.intel.com, david@redhat.com, luto@kernel.org, vbabka@suse.cz, marcorr@google.com, erdemaktas@google.com, pgonda@google.com, nikunj@amd.com, seanjc@google.com, diviness@google.com, Shuah Khan References: <20220511000811.384766-1-vannapurve@google.com> <20220511000811.384766-4-vannapurve@google.com> From: Shuah Khan Message-ID: <934a07be-ce72-7916-5614-e78af8293b5c@linuxfoundation.org> Date: Thu, 12 May 2022 11:40:57 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20220511000811.384766-4-vannapurve@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On 5/10/22 6:08 PM, Vishal Annapurve wrote: > Add handling of explicit private/shared memory conversion using > KVM_HC_MAP_GPA_RANGE and implicit memory conversion by handling > KVM_EXIT_MEMORY_ERROR. > > Signed-off-by: Vishal Annapurve > --- > tools/testing/selftests/kvm/priv_memfd_test.c | 87 +++++++++++++++++++ > 1 file changed, 87 insertions(+) > > diff --git a/tools/testing/selftests/kvm/priv_memfd_test.c b/tools/testing/selftests/kvm/priv_memfd_test.c > index bbb58c62e186..55e24c893b07 100644 > --- a/tools/testing/selftests/kvm/priv_memfd_test.c > +++ b/tools/testing/selftests/kvm/priv_memfd_test.c > @@ -155,6 +155,83 @@ static struct test_run_helper priv_memfd_testsuite[] = { > }, > }; > > +static void handle_vm_exit_hypercall(struct kvm_run *run, > + uint32_t test_id) > +{ > + uint64_t gpa, npages, attrs; > + int priv_memfd = > + priv_memfd_testsuite[test_id].priv_memfd; Do you need this on a separate line? Doesn't looks like it will exceed the limit with the tab? > + int ret; > + int fallocate_mode; > + > + if (run->hypercall.nr != KVM_HC_MAP_GPA_RANGE) { > + TEST_FAIL("Unhandled Hypercall %lld\n", > + run->hypercall.nr); Is this considered test fail or skip because of unmet dependency? Also do you need run->hypercall.nr os a separate line? > + } > + > + gpa = run->hypercall.args[0]; > + npages = run->hypercall.args[1]; > + attrs = run->hypercall.args[2]; > + > + if ((gpa < TEST_MEM_GPA) || ((gpa + > + (npages << MIN_PAGE_SHIFT)) > TEST_MEM_END)) { > + TEST_FAIL("Unhandled gpa 0x%lx npages %ld\n", > + gpa, npages); Same question here about gpa, npages on a separate line? Also align it with the previous line for readability. TEST_FAIL("Unhandled gpa 0x%lx npages %ld\n", gpa, npages); > + } > + > + if (attrs & KVM_MAP_GPA_RANGE_ENCRYPTED) > + fallocate_mode = 0; > + else { > + fallocate_mode = (FALLOC_FL_PUNCH_HOLE | > + FALLOC_FL_KEEP_SIZE); > + } > + pr_info("Converting off 0x%lx pages 0x%lx to %s\n", > + (gpa - TEST_MEM_GPA), npages, > + fallocate_mode ? > + "shared" : "private"); > + ret = fallocate(priv_memfd, fallocate_mode, > + (gpa - TEST_MEM_GPA), > + npages << MIN_PAGE_SHIFT); > + TEST_ASSERT(ret != -1, > + "fallocate failed in hc handling"); > + run->hypercall.ret = 0; > +} > + > +static void handle_vm_exit_memory_error(struct kvm_run *run, > + uint32_t test_id) > +{ > + uint64_t gpa, size, flags; > + int ret; > + int priv_memfd = > + priv_memfd_testsuite[test_id].priv_memfd; > + int fallocate_mode; > + > + gpa = run->memory.gpa; > + size = run->memory.size; > + flags = run->memory.flags; > + > + if ((gpa < TEST_MEM_GPA) || ((gpa + size) > + > TEST_MEM_END)) { > + TEST_FAIL("Unhandled gpa 0x%lx size 0x%lx\n", > + gpa, size); > + } > + > + if (flags & KVM_MEMORY_EXIT_FLAG_PRIVATE) > + fallocate_mode = 0; > + else { > + fallocate_mode = (FALLOC_FL_PUNCH_HOLE | > + FALLOC_FL_KEEP_SIZE); > + } > + pr_info("Converting off 0x%lx size 0x%lx to %s\n", > + (gpa - TEST_MEM_GPA), size, > + fallocate_mode ? > + "shared" : "private"); > + ret = fallocate(priv_memfd, fallocate_mode, > + (gpa - TEST_MEM_GPA), size); > + TEST_ASSERT(ret != -1, > + "fallocate failed in memory error handling"); > +} > + > static void vcpu_work(struct kvm_vm *vm, uint32_t test_id) > { > struct kvm_run *run; > @@ -181,6 +258,16 @@ static void vcpu_work(struct kvm_vm *vm, uint32_t test_id) > continue; > } > > + if (run->exit_reason == KVM_EXIT_HYPERCALL) { > + handle_vm_exit_hypercall(run, test_id); > + continue; > + } > + > + if (run->exit_reason == KVM_EXIT_MEMORY_ERROR) { > + handle_vm_exit_memory_error(run, test_id); > + continue; > + } > + > TEST_FAIL("Unhandled VCPU exit reason %d\n", run->exit_reason); > break; > } > Looks like you can easily combine lines without running into # chars limit for several lines of code in this patch. If you haven't already, run checkpatch to make sure coding guidelines are honored. thanks, -- Shuah