Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2515939rdb; Fri, 22 Sep 2023 00:18:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEVnSlBQINRYnvCZl2ReyuSwLtyVozNvcKNpXoQcT4yxvhQZlxRb7+W9kpnOxztFOgA7Wkm X-Received: by 2002:a17:90b:17d2:b0:274:77df:50d1 with SMTP id me18-20020a17090b17d200b0027477df50d1mr7333496pjb.21.1695367110547; Fri, 22 Sep 2023 00:18:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695367110; cv=none; d=google.com; s=arc-20160816; b=Vnv9c4W8ZGtAJqv0ZgpqJCo1Ph78GDgIGkEskwYWwh1KkPSNS5/z635y7RmZvbYKZH /x5Wcui2BkLpvf41CdRBZB3a1XCBYPYrKmph0nGxp0qcFIDSCdbMAeVzeyWyajxzJwKN 9kCxeb3/kxt9lmC7VTEb1Ga40JLM4ABoOFFYK2sZRAAqZIm9KnHEf2Cn/mbPJnzSZU2r UZeqcULICti64pGSqM8/QwdK9i+wwgLkiJjEBqcWxJS8hdvwWOlz9bG7xI2qUL0Yzrkg IyHh5wFiU2aJN2knjywCKL6/1Fnfxe3icL3kFIL7CQgRgJwJy0Zw7rl2ZHOJb1RWbeXR NNzw== 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=I7bkyRILGQE7yWTmbQXiGKEo0p9CYB75A1OQz7APl7U=; fh=4zSMCzNb7rJrUGZtbNPceVM+tszI9ngqwF5WBZpI8NM=; b=pML4oaa5ZMwCmQUnvucqLAGJ96pXBC+yW/5PxxQLxZpo7tddkFngRKTcGFO3KMJBeQ cyp12AchCyTyfuoQPKaiab1cQT5MS9QsIBvCF2Vmucqku2HwJCA661uwRvanNSuxg5m2 ESXJuMHw83r3QtZsKVArmAKX0ecbrkRG6wjk1HZAuw8/5koXKwrG9Kr0lA6keM642Qw4 GF4cywzQbS3BOKLwZGumkA92PWhRdVaxiE9sgNbMbekKgK3NCNv7E47YJGEMpNinJ548 mvx4Xg9SZKI/PrdCfsWAV8dMphrs5lvMEzBY4ux33o7MD2SykklY4zVJUKhMi2Ej8Bnb 2Rbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0hloQHuZ; 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 fw3-20020a17090b128300b002639acf55c7si5398532pjb.7.2023.09.22.00.18.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:18:30 -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=0hloQHuZ; 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 3C3738352EDF; Thu, 21 Sep 2023 16:22:49 -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 S229490AbjIUXWt (ORCPT + 99 others); Thu, 21 Sep 2023 19:22:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229532AbjIUXWr (ORCPT ); Thu, 21 Sep 2023 19:22:47 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD5F211A for ; Thu, 21 Sep 2023 16:22:40 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d8186d705a9so2134289276.3 for ; Thu, 21 Sep 2023 16:22:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695338560; x=1695943360; 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=I7bkyRILGQE7yWTmbQXiGKEo0p9CYB75A1OQz7APl7U=; b=0hloQHuZm4kw+GLf+XzEbwSz7VgbGzWdjly9NkDAk617soopbzpgGP7Nb5A77X1HKb Efbw8bJsGZfOP/SlWMAi6uzNfzXSPPvUL5i/5eRf8yPFn+4Geli1z8X2LKrYUM+cruF4 NjSItMMkZ3LAN6/kAy2RC0uh3RAFhVCR30VAe/0r968XtLqX/XNNNPgjIcjNLxYTr9F/ Wu9rOtQSPiJ8G3/r3Xm17BVoBZPIVz+2qcZEBAK9lbnt7bMG1QGVNl5c2FOiX/U0NsdX K5aVsd2Acvc7O0mYeks10zktzq5Jxi3OXF37xd5gjoJNokS3HS4Sy+ljUOwlPBAfSett v8iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695338560; x=1695943360; 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=I7bkyRILGQE7yWTmbQXiGKEo0p9CYB75A1OQz7APl7U=; b=GEb5LJsnhJm9MTvM/9zp5Sxi/a0Sb3fiLXuWaVm+IxLrktxoOnCoTkZF37XLrAIdWZ hJsFAcjmQQfQcpd3bELf1UJzjm152JFCsEwpTa7HdkcFmT0aB8a8ZU9Uk5fSj71M4k7t U/OWkRZpxZ/u5uWnjPdyYBqWujRHjgq2akEcOZG6QQOzevTQfUoJDZn5abNioNwGdybx re6r5vK/6xzuU5MwrZWEGiIAPbeYWO6w2Ye4VsGV+uOhAsmEQ1jN8Q6KfMtbByU/5mJ0 tpvDkxTYtSIzXZei9gL79kj98k5UDFc5DefpVkbDWcd1r0xvNOCZdOelkN5Afk5A/Cb4 eY6A== X-Gm-Message-State: AOJu0Yx/o2KoVT3UHO8uxSOUYGcsJVOi7BP/qp4kLLOJ2xvR9fuuleRe NfNj5kBY0ZcxgmB5pY3SPW26gIvWu1o= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:746:0:b0:d05:98ef:c16b with SMTP id 67-20020a250746000000b00d0598efc16bmr943ybh.5.1695338559807; Thu, 21 Sep 2023 16:22:39 -0700 (PDT) Date: Thu, 21 Sep 2023 16:22:38 -0700 In-Reply-To: <7fddbf10494490251f2156fd600306991826165f.1695327124.git.isaku.yamahata@intel.com> Mime-Version: 1.0 References: <7fddbf10494490251f2156fd600306991826165f.1695327124.git.isaku.yamahata@intel.com> Message-ID: Subject: Re: [RFC PATCH v2 6/6] KVM: guest_memfd: selftest: Add test case for error_remove_page method 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" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 21 Sep 2023 16:22:49 -0700 (PDT) On Thu, Sep 21, 2023, isaku.yamahata@intel.com wrote: > From: Isaku Yamahata > > This test case implements fault injection into guest memory by > madvise(MADV_HWPOISON) for shared(conventional) memory region and > KVM_GUEST_MEMORY_FAILURE for private gmem region. Once page is poisoned, > free the poisoned page and try to run vcpu again to see a new zero page is > assigned. Thanks much for the test! I think for the initial merge it makes sense to leave this out, mainly because I don't think we want a KVM specific ioctl(). But I'll definitely keep this around to do manual point testing. > +#define BASE_DATA_SLOT 10 > +#define BASE_DATA_GPA ((uint64_t)(1ull << 32)) > +#define PER_CPU_DATA_SIZE ((uint64_t)(SZ_2M)) > + > +enum ucall_syncs { > + HWPOISON_SHARED, > + HWPOISON_PRIVATE, > +}; > + > +static void guest_sync_shared(uint64_t gpa) Probably guest_poison_{shared,private}(), or maybe just open code the GUEST_SYNC2() calls. I added helpers in the other tests because the ucalls were a bit more involved then passing the GPA. However, I don't see any reason to do hypercalls and on-demand mapping/fallocate. Just have two separate sub-tests, one for private and one for shared, each with its own host. I'm pretty sure the guest code can be the same, e.g. I believe it would just boil down to: static void guest_code(uint64_t gpa) { uint64_t *addr = (void *)gpa; WRITE_ONCE(*addr, ); /* Ask the host to poison the page. */ GUEST_SYNC(EWPOISON); /* * Access the poisoned page. The host should see a SIGBUS or EHWPOISON * and then truncate the page. After truncation, the page should be * faulted back and read zeros, all before the read completes. */ GUEST_ASSERT_EQ(*(uint64_t *)gpa, 0); GUEST_DONE(); } > + if (uc.args[0] == HWPOISON_PRIVATE) { > + int ret; > + > + inject_memory_failure(gmem_fd, gpa); > + ret = _vcpu_run(vcpu); > + TEST_ASSERT(ret == -1 && errno == EHWPOISON && Honestly, I'm kinda surprised the KVM code actually works :-) > + run->exit_reason == KVM_EXIT_MEMORY_FAULT, > + "exit_reason 0x%x", > + run->exit_reason); > + /* Discard the poisoned page and assign new page. */ > + vm_guest_mem_fallocate(vm, gpa, PAGE_SIZE, true); > + } else { > + uint8_t *hva = addr_gpa2hva(vm, gpa); > + int r; > + > + r = madvise(hva, 8, MADV_HWPOISON); Huh. TIL there's an MADV_HWPOISON. We've already talked about adding fbind(), adding an fadvise() seems like the obvious solution. Or maybe overload fallocate() with a new flag? Regardless, I think we should add or extend a generic fd-based syscall(), not throw in something KVM specific.