From patchwork Wed Jan 16 17:41:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gardon X-Patchwork-Id: 10766475 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EBC7591E for ; Wed, 16 Jan 2019 17:41:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D30832F17D for ; Wed, 16 Jan 2019 17:41:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C29ED2F312; Wed, 16 Jan 2019 17:41:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 664282F17D for ; Wed, 16 Jan 2019 17:41:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726806AbfAPRlb (ORCPT ); Wed, 16 Jan 2019 12:41:31 -0500 Received: from mail-qt1-f202.google.com ([209.85.160.202]:44702 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726754AbfAPRlb (ORCPT ); Wed, 16 Jan 2019 12:41:31 -0500 Received: by mail-qt1-f202.google.com with SMTP id j5so6252735qtk.11 for ; Wed, 16 Jan 2019 09:41:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=x6aPte6KyEF/OPBPFEKCAtrySvpgez8hC++u6424PaA=; b=Ys7AO1KGaYH2knNnLq5zjDyFzQudZy5R77FNV4vbYjRzDh7TsmwJbkMc7DXgitpLBm Ocx+xI+JdOXi7PFSfRJ9PGvwGEGMF4bauRuzdbVxLH4kBJqOabEp4OfuhYtmR+nPILRK imNEEJXKzbQY4BgRMnwhjDXpXOdv/1gL+h+PfvVDY1US+u9iUZ6iFt/d3SE95yzdysGV hW4wGi50ksBv1QnTpvZAKpKhzy93Eqxx/4Hv4hZPis/s2FmgC8MSwv6Vs6zVeVghLR3a kb/+HT/hdDbEkD+XdJc2mOIO6Gwst1HVU/N7wSDzxPQPE72mKOZFq4IBZAG+Ug2j3x7O o9bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=x6aPte6KyEF/OPBPFEKCAtrySvpgez8hC++u6424PaA=; b=ui5xolN1CNs6ytsQdW90kaMhMmEJAzEudr5dMHvFroan1BsXDihx0KRHJ+DmYzDUA4 HTHAsvx4zTMq5krhKiUfeszSFQPURMR+9HpVBRzKis5NpoAWLVSXB2FOE5cUjFBUQtSg XLKrqXpe4uDbRWwPc4diITYYoT4VIkIF0B/Zd2jAzbcKl5XnkfPG7wn0ywIQjm0Eyffu 1sOOlVEWj9B3HB3kTC4lSQ1FqT3WlaO7ptz0keap0Ma5L6dpDrJXBLAf3xAb+s7lduyQ LzWJdGCR9bJnYq4qa41KY5ldmhX0zXu7n71uA2FilVBMut3Fbrg5GOOm3HU4uilHe1pg xmxw== X-Gm-Message-State: AJcUukcNkYbsbMLI0cOCffq5RxebC9gkLYlv5CsiNNO8zsrisw2VVYM2 m34dC1Se/8hTPQKmtpQwRANEc9Lzk2pP X-Google-Smtp-Source: ALg8bN7pADi0QrtuZZvED/O+9rohgxC/1/XiLPFo4DobvrAY6U9LaXggFjtt2QIj7qs/jr0M8JEMTtvKMRwl X-Received: by 2002:a37:9042:: with SMTP id s63mr5580248qkd.10.1547660490152; Wed, 16 Jan 2019 09:41:30 -0800 (PST) Date: Wed, 16 Jan 2019 09:41:15 -0800 Message-Id: <20190116174115.95225-1-bgardon@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog Subject: [PATCH v2] kvm: selftests: Fix region overlap check in kvm_util From: Ben Gardon To: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Paolo Bonzini , Andrew Jones , " =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= " , Ben Gardon , Jim Mattson Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix a call to userspace_mem_region_find to conform to its spec of taking an inclusive, inclusive range. It was previously being called with an inclusive, exclusive range. Also remove a redundant region bounds check in vm_userspace_mem_region_add. Region overlap checking is already performed by the call to userspace_mem_region_find. Tested: Compiled tools/testing/selftests/kvm with -static Ran all resulting test binaries on an Intel Haswell test machine All tests passed Signed-off-by: Ben Gardon Reviewed-by: Jim Mattson Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/lib/kvm_util.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 23022e9d32eb81..b52cfdefecbfe9 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -571,7 +571,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, * already exist. */ region = (struct userspace_mem_region *) userspace_mem_region_find( - vm, guest_paddr, guest_paddr + npages * vm->page_size); + vm, guest_paddr, (guest_paddr + npages * vm->page_size) - 1); if (region != NULL) TEST_ASSERT(false, "overlapping userspace_mem_region already " "exists\n" @@ -587,15 +587,10 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, region = region->next) { if (region->region.slot == slot) break; - if ((guest_paddr <= (region->region.guest_phys_addr - + region->region.memory_size)) - && ((guest_paddr + npages * vm->page_size) - >= region->region.guest_phys_addr)) - break; } if (region != NULL) TEST_ASSERT(false, "A mem region with the requested slot " - "or overlapping physical memory range already exists.\n" + "already exists.\n" " requested slot: %u paddr: 0x%lx npages: 0x%lx\n" " existing slot: %u paddr: 0x%lx size: 0x%lx", slot, guest_paddr, npages,