From patchwork Fri Feb 23 00:42:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13568416 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 046B9C54E41 for ; Fri, 23 Feb 2024 00:45:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HRsJsn+GOylZuPDABgjgxGxbv2bUtZR9NiKUC4z4OnU=; b=AAtAacs7w/vZtb W5DaZO1BGkaedFatSibxUKmSPno8wFc21nTUsbvSbykzRx5+KzLqvOMrIi7yQS8agwuGzigZ86651 KFJabP3/JxFVwrM2NCIR0hptwgQs9967waUz/aplmHM82BiVkn+K6ccYbwUq+gLO0u1Dy7bkc71RT zewQnep9kEoqfLKvvqKUmE/GzA0FzzP5yYfug3ADYszoE9rRjhQ5MFqiq9rV9PMvEJJ4SWQmPWXp4 sBIF9bDH+QEDfggsrrHmrAXL3XP2hD0iXGhD9Sitg14ihHy9jIyiIpoeBxTn6RG96u5SnGml+9nF3 D+NTzSlgEGlGK/+UsM/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdJgT-00000007Ei8-0tLA; Fri, 23 Feb 2024 00:45:01 +0000 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdJeh-00000007Doq-2C8f for linux-arm-kernel@lists.infradead.org; Fri, 23 Feb 2024 00:43:16 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-6e4597a3ff3so236317b3a.0 for ; Thu, 22 Feb 2024 16:43:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708648987; x=1709253787; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=jhSBUfusWJ3ofLKWMGpg2YDRgo1XDnuJP2HRidQqwH4=; b=EVRQFYwZWLh0Yw8Qp4ksR19DJRYuKltIYM7FQ4nR26r9xOcx05GgCHEX0yLgtcBZza Kdq0Nit72SDS6sXLwrqKUf3FYuuDN/EpPrcpebEvVJuQuYID7eGlvs0Tquxl3myMwoEB YrhEpCUu8NCU/QsVoEH/6W3slpQ7fkVIgUZYICGtSDnApMdessE0bFm1MV+PQ6XqatBs dqoiMjc1DWyL9JNS4PWsT6wy+u4fMCiH/GM7OJ36icwwWVKnxPxCOXDUNFgqN6GUM6Nc T5OaeVVnGREkkjX3OOXjkJbsg+HHFy3cnquMLNKBLI6dLZZ7ReaU2WxvHu3Z+oUTZ17U gF5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708648987; x=1709253787; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jhSBUfusWJ3ofLKWMGpg2YDRgo1XDnuJP2HRidQqwH4=; b=LuywSKXXJq9sPlFsnjr10zbDZ1WXN8QJ+fJr5km5EshqQ0x9VmRcYu1etqVbyiGuPH W4waGusAXaVp5L7atJvaJdAWBJdlem7dS+aG038j4rrJkpDxztWKKkStDGedNUf9Zobe 4d5ib2Y8FwJ3bV1R8Y4p99gLOP/Ovr/7G5HzaH7K1L3d/fu25KvG1y4rJb98uxtxDesJ d4RTjiqxNYAz651Jfc3KSIAhwKK4tsTa2E3o487oaNaSDAmlVgKUTsN3z7hlqvboJ79+ DTWN130E2C+MATCCGAmW/kVoCdWa7r6YgsMtG0qLhBo09V8bZEMx9gtlHNgiA5HFXlRh Zx9Q== X-Forwarded-Encrypted: i=1; AJvYcCXXONhQX2zq84R32Y/ianLCmbO4RLGlsF1ctmKBjEkJSh1C7VGMdOneOTvn5iTmc2FyxYxLuFUxUjWIWF80uVDhL+EqLHwaUd0kUvrmIF6LIuu75ZA= X-Gm-Message-State: AOJu0YzOwpLbFhdgMij17mbbCuXPwOVrhZYL+KRthnmJ0swmGLV93jY4 14NhQrqy+83gPb7VkN96V2VMHxNtaWuSrYDzlD/kGeS/W++cf1uUD1MIqr/+RS1pfx76Rjb1qwK kIw== X-Google-Smtp-Source: AGHT+IHIxuf373oGf69Al+lWSIf6Q+TRpWLvL/aYM1tJ8IvZSlPzsioXOjltEzRkvK0lvpvWJZPUowBn/iU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:22cd:b0:6e4:643e:e215 with SMTP id f13-20020a056a0022cd00b006e4643ee215mr24254pfj.3.1708648987517; Thu, 22 Feb 2024 16:43:07 -0800 (PST) Date: Thu, 22 Feb 2024 16:42:50 -0800 In-Reply-To: <20240223004258.3104051-1-seanjc@google.com> Mime-Version: 1.0 References: <20240223004258.3104051-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240223004258.3104051-4-seanjc@google.com> Subject: [PATCH v9 03/11] KVM: selftests: Add a macro to iterate over a sparsebit range From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Vishal Annapurve , Ackerley Tng , Andrew Jones , Tom Lendacky , Michael Roth , Carlos Bilbao , Peter Gonda , Itaru Kitayama X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240222_164312_290529_89FD944B X-CRM114-Status: GOOD ( 12.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ackerley Tng Add sparsebit_for_each_set_range() to allow iterator over a range of set bits in a range. This will be used by x86 SEV guests to process protected physical pages (each such page needs to be encrypted _after_ being "added" to the VM). Tested-by: Carlos Bilbao Signed-off-by: Ackerley Tng [sean: split to separate patch] Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/include/sparsebit.h | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/testing/selftests/kvm/include/sparsebit.h b/tools/testing/selftests/kvm/include/sparsebit.h index fb5170d57fcb..bc760761e1a3 100644 --- a/tools/testing/selftests/kvm/include/sparsebit.h +++ b/tools/testing/selftests/kvm/include/sparsebit.h @@ -66,6 +66,26 @@ void sparsebit_dump(FILE *stream, const struct sparsebit *sbit, unsigned int indent); void sparsebit_validate_internal(const struct sparsebit *sbit); +/* + * Iterate over an inclusive ranges within sparsebit @s. In each iteration, + * @range_begin and @range_end will take the beginning and end of the set + * range, which are of type sparsebit_idx_t. + * + * For example, if the range [3, 7] (inclusive) is set, within the + * iteration,@range_begin will take the value 3 and @range_end will take + * the value 7. + * + * Ensure that there is at least one bit set before using this macro with + * sparsebit_any_set(), because sparsebit_first_set() will abort if none + * are set. + */ +#define sparsebit_for_each_set_range(s, range_begin, range_end) \ + for (range_begin = sparsebit_first_set(s), \ + range_end = sparsebit_next_clear(s, range_begin) - 1; \ + range_begin && range_end; \ + range_begin = sparsebit_next_set(s, range_end), \ + range_end = sparsebit_next_clear(s, range_begin) - 1) + #ifdef __cplusplus } #endif