Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp198056imj; Thu, 14 Feb 2019 18:29:58 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib3/dd+jKJgfRezAlCCC8Jl5w7Vh2jZgWcD23XcUxEkToByq+/toQm3PupLGDIGV86LWo6M X-Received: by 2002:a63:ef04:: with SMTP id u4mr3079922pgh.197.1550197798379; Thu, 14 Feb 2019 18:29:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550197798; cv=none; d=google.com; s=arc-20160816; b=FxmFTuEt1GUop6z4GKDYyiwTnFduzq8YHaTSmagf4g2CILixtBF8TulWpqWsri55Ft Q1oG92vqnrpsDRLBxod72aRGI2WRKv/1u4OfmQoY9OD9ACgXd3rbxGxlmEY13091k/Gw bHvwu3dCK8SHF6O00E9gXgji2ZvlUghOrRuB8fVHlhpAdw+G9TeDOA19D9vAlJ2mDfAY v4UvjneYz+L827CDYxUSu3oAHH9Uiyex+GxHvcdzs62nJFbyKFcMn0tkcJPg1y5q0boT bJJHoz5rDY84l+Weu5k4DPVyqMhYBBAAaRNhfF4rsbecJ51dwQiI26V8jR4kmszW6iB/ bGKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9H6IIxyzTOtNfi+YVy15mgc5FkORtOQCQXpNzOFCVQI=; b=XhR07zYH1U5Fknkr6vTNF9kGRGHWE2pndjSuQDZYglCgPWu4AXd00lozJaYcd4eW5z IlAw7sG5D7fnkwhDCHXTD20boQZIi7WWNBtNVJL+f7foLSKebEoNHKEGfBDwNJKEkUyB c4SRgMyFKqQmTyr8uJzqNIGYGZdFMfMuaHO2Cl4nYrB1yP2rjG42Te/rJ+on0G/KSaFa IA2ZsztgSk6wVuylh419d+4rykP8s8BU2sZD1moKMRSFshQU8Uu1gGEyna21lkMFxSqa w+/KS0I4Feezx0YrT0j3KP3JsNWxM9Lvc4c+/DWuKCoVcm4Eh4QgJQ706b9/rdw/vXBW glFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YjuSEg5R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4si4213391pfa.150.2019.02.14.18.29.42; Thu, 14 Feb 2019 18:29:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YjuSEg5R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732203AbfBOCLP (ORCPT + 99 others); Thu, 14 Feb 2019 21:11:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:51292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbfBOCLM (ORCPT ); Thu, 14 Feb 2019 21:11:12 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 006AD21934; Fri, 15 Feb 2019 02:11:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550196671; bh=u8Wx9GsMXcZZYeBBNGwlq656t69YYYMVAFRicoNjviU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YjuSEg5RzyUfef3PtMlhD7zPmXHqILj2ViaH6TV2qoHgshsjgjXzUybilbAchVAHb 8tcMf22ZlpVBq0468BMbRTJ3eLzFHA2/KS4y1/xzbZR2rauXhtZobhDrJK4ibtf6UC nPm6yc7PcYRSdkEJ6xjOiS+BpIgFsqK/mdoLIKHc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ben Gardon , Paolo Bonzini , Sasha Levin , linux-kselftest@vger.kernel.org Subject: [PATCH AUTOSEL 4.20 75/77] kvm: selftests: Fix region overlap check in kvm_util Date: Thu, 14 Feb 2019 21:08:53 -0500 Message-Id: <20190215020855.176727-75-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190215020855.176727-1-sashal@kernel.org> References: <20190215020855.176727-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ben Gardon [ Upstream commit 94a980c39c8e3f8abaff5d3b5bbcd4ccf1c02c4f ] 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 Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- 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 1b41e71283d5..6ee49133ad22 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -532,7 +532,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" @@ -548,15 +548,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, -- 2.19.1