Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1064261pxb; Fri, 22 Apr 2022 18:22:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxadqGucsNKVI16XW4NOb5qqMKkTboWdIHyO9slkjlBe4sTi+LpDHn3+Y2RxRddAE0jffyB X-Received: by 2002:a17:902:8ec2:b0:156:9d2c:9ec5 with SMTP id x2-20020a1709028ec200b001569d2c9ec5mr7140071plo.170.1650676933329; Fri, 22 Apr 2022 18:22:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650676933; cv=none; d=google.com; s=arc-20160816; b=rehUEJGRh8gINCGSO+8q+a3IlPgPOyN2GNtfwVjxPWsikHYKoI65fVvadKCHSs1cs/ avevWG4/K1JzUvMOzkK4XBvbjotBXK76SN50oaC3z1fxkjdYD4VMOIPMw+VThwUFmqR6 2kB/PJsM1sidHntWOnwdHJgtKQo+ojyDTQRtcdTfAmZk9JQnm2Lve+OVYV3nzioI7HjG JJQ7kBCiCvwtz4zUUjn7UwfpB6yI8z4KyulTeveQzpHEsiM3cHdV50N8+muPxTDSvpI3 plElWJiMC2XFKOVe9whyW7fKxkFo6WgnLFZpZgubVeteGDVQ7MMyVQs8gI5WfWglhK9j Vtkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=6AW/tHyGYH7buMqMi2HrCUPQKHLBIz8Z8Mq8CEPo14E=; b=hP1ruBFEvknZ+TuuX1I4eV/PPae4U+Xr+Um/xbmLFq5BgSB0Aabf9OwxV2lQvArZkz f8z0O4MthV93HdevM0RQ4vkYkmWAlwLez4Czm1F/wAj+/Gjwiy55ZAeubbKmTahZFBQ/ iYYGtiwdz5Eh1meLhvDU2AMHmaOpFG4AflkzeuRZFhD6sbcudcQPNasdhgDwcItamZ+f OSIJTETUsy4Fq9ArvtIgdMS+GBwDcwToOb5cW3Yp+AP3XJod3f1+hVHMWwvCG4OHD3r3 fc48QZ/y8SKVwCTOSa9tH3TMNcDFk+DacT5oxaliHunkmOueUoROLptOPQ/00FM3pVaY FrGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b="Yy/eAe26"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x141-20020a627c93000000b004fa3a8dfffbsi8596778pfc.178.2022.04.22.18.21.44; Fri, 22 Apr 2022 18:22:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b="Yy/eAe26"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231307AbiDWBLI (ORCPT + 99 others); Fri, 22 Apr 2022 21:11:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbiDWBLH (ORCPT ); Fri, 22 Apr 2022 21:11:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB0A71D51A8; Fri, 22 Apr 2022 18:08:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 77A8F60FF7; Sat, 23 Apr 2022 01:08:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2231BC385A0; Sat, 23 Apr 2022 01:08:10 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="Yy/eAe26" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1650676088; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6AW/tHyGYH7buMqMi2HrCUPQKHLBIz8Z8Mq8CEPo14E=; b=Yy/eAe26VKr7OGfH2Y6VmzQOHrBaFcJLcZFxCIwoM5GuWBkc2pVHJvNsZCnWn7qW3IE260 elg/9Ox4JG1Pse8sMQB6nuBzab/le2Ft81PiwE6ZwKadRJyrJbbMWUX6Sn6qMScxZY19r8 ci2DLY0hWVYObTdHGli6SRfrLCitsj4= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id ff5900aa (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sat, 23 Apr 2022 01:08:08 +0000 (UTC) Date: Sat, 23 Apr 2022 03:08:04 +0200 From: "Jason A. Donenfeld" To: =?utf-8?Q?Charles-Fran=C3=A7ois?= Natali Cc: wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-crypto@vger.kernel.org, Daniel Jordan , Steffen Klassert Subject: Re: [PATCH] WireGuard: restrict packet handling to non-isolated CPUs. Message-ID: References: <20220405212129.2270-1-cf.natali@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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-crypto@vger.kernel.org Hi Charles, On Fri, Apr 22, 2022 at 11:23:01PM +0100, Charles-François Natali wrote: > > Regarding your patch, is there a way to make that a bit more succinct, > > without introducing all of those helper functions? It seems awfully > > verbose for something that seems like a matter of replacing the online > > mask with the housekeeping mask. > > Indeed, I wasn't really happy about that. > The reason I've written those helper functions is that the housekeeping mask > includes possible CPUs (cpu_possible_mask), so unfortunately it's not just a > matter of e.g. replacing cpu_online_mask with > housekeeping_cpumask(HK_FLAG_DOMAIN), we have to perform an AND > whenever we compute the weight, find the next CPU in the mask etc. > > And I'd rather have the operations and mask in a single location instead of > scattered throughout the code, to make it easier to understand and maintain. > > Happy to change to something more inline though, or open to suggestions. Probably more inlined, yea. A simpler version of your patch would probably be something like this, right? diff --git a/drivers/net/wireguard/queueing.h b/drivers/net/wireguard/queueing.h index 583adb37ee1e..b3117cdd647d 100644 --- a/drivers/net/wireguard/queueing.h +++ b/drivers/net/wireguard/queueing.h @@ -112,6 +112,8 @@ static inline int wg_cpumask_choose_online(int *stored_cpu, unsigned int id) cpu = cpumask_first(cpu_online_mask); for (i = 0; i < cpu_index; ++i) cpu = cpumask_next(cpu, cpu_online_mask); + while (!housekeeping_test_cpu(cpu, HK_???)) + cpu = cpumask_next(cpu, cpu_online_mask); *stored_cpu = cpu; } return cpu; @@ -128,7 +130,7 @@ static inline int wg_cpumask_next_online(int *next) { int cpu = *next; - while (unlikely(!cpumask_test_cpu(cpu, cpu_online_mask))) + while (unlikely(!cpumask_test_cpu(cpu, cpu_online_mask) && !housekeeping_test_cpu(cpu, HK_???))) cpu = cpumask_next(cpu, cpu_online_mask) % nr_cpumask_bits; *next = cpumask_next(cpu, cpu_online_mask) % nr_cpumask_bits; return cpu; However, from looking at kernel/sched/isolation.c a bit, I noticed that indeed you're right that most of these functions (save one) are based on cpu_possible_mask rather than cpu_online_mask. This is frustrating because the code makes smart use of static branches to remain quick, but ANDing housekeeping_cpumask() with cpu_online_mask would, in the fast path, wind up ANDing cpu_online_mask with cpu_possible_mask, which is silly and pointless. That makes me suspect that maybe the best approach would be adding a relevant helper to kernel/sched/isolation.c, so that the helper can then do the `if (static_branch_unlikely(&housekeeping_overridden))` stuff internally. Or maybe you'll do some measurements and decide that just [ab]using housekeeping_test_cpu() like above is actually optimal? Not really sure myself. Anyway, I'll keep an eye out for your joint wireguard/padata series. Be sure to CC the people who wrote the isolation & housekeeping code, as they likely have opinions about this stuff (and certainly know more than me about it). Jason