From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by sourceware.org (Postfix) with ESMTPS id 391493858D39 for ; Wed, 15 Mar 2023 15:25:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 391493858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-5419d4c340aso190061467b3.11 for ; Wed, 15 Mar 2023 08:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678893953; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Jp4FDM8h6U+Mas4a2rvkDaEwOlJdGcAEgDm20M+I8f8=; b=Qey4MMaERANuKtI/BrYMxnHlsBv4sWvuU6KTvl+EjDQrE1dZAw+bmP5BcOOzAhWJCS eC1egFnLG1Q0DkwcciQF3kA59BwCSy+suwnMnHcNDq1ZsGnd5v/y1vrUeZAQMQMsOQf/ U68t7i2y7fXZPmrIp1Zrw/IJZgAF/qjmGXxnbPIo4LGmR+IRj7HL4I6tBrkX0/guPE2d PO37PL9HPM/+yNy7X7GuBzQv1prlgaYmYtwDkBfvUAwBkz6YSKhyJj94pHJnPR4vGBVW jG75i9dGI3goNbBV8fyHQD+R932J1R7tou73MH6oyBNxYalE+HCbAH4HToR481K5wZ6K tO4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678893953; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jp4FDM8h6U+Mas4a2rvkDaEwOlJdGcAEgDm20M+I8f8=; b=zgi2w/Km8x14inQe/ab4o6dAPJvH48jLAweg9R9FuIVlqDs1jOvozswjOxlstywnAh ePKQ5dc2zLFYwC01K23YSKcq2nfsgCTAX6IZtAbJQqYAx71uzEYTZCyepwavovJ/5ce0 k3jDHz1dFMpDebWsClUIx418R2FZDz5ktCZtOrzhDhm10BJ8JxveudxY2ouoGtgo3ruV fiGu07cJSN4PXcxtcKpFYYHkhaztQIPRgjxRqWCJJWD9dTiOKMk824vt2RBFoRBdEL2U Ys3Ix17TfdYiNz+GsyDBY8aWwYV4Ft7rEH/ZO8gF/R8oprcsnFYP1WsDyh9aHCZfZzPk kr8A== X-Gm-Message-State: AO0yUKUqltoc9AM3ofiEE66FHrhQJeLYzvHSNlxxUS2xFH06LZilivQd emRIWx1rnB+qjm7FYgnHM6YdQeYk+57rINbHbAm5VnsQ X-Google-Smtp-Source: AK7set/xrBBqsNKb+AWyrjCTOz1ObUj/TryTnk1eBQ4NiMAIBlP6I+maHjPZdlDVaxYj7qn42MWpGjKyWR39NugnqhM= X-Received: by 2002:a81:c606:0:b0:541:9063:8e9e with SMTP id l6-20020a81c606000000b0054190638e9emr188258ywi.2.1678893953399; Wed, 15 Mar 2023 08:25:53 -0700 (PDT) MIME-Version: 1.0 References: <20230103210648.2569652-1-hjl.tools@gmail.com> In-Reply-To: From: "H.J. Lu" Date: Wed, 15 Mar 2023 08:25:17 -0700 Message-ID: Subject: Re: [PATCH v2] x86: Check minimum/maximum of non_temporal_threshold [BZ #29953] To: Libc-stable Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3022.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Jan 3, 2023 at 1:15=E2=80=AFPM Noah Goldstein wrote: > > On Tue, Jan 3, 2023 at 1:06 PM H.J. Lu wrote: > > > > The minimum non_temporal_threshold is 0x4040. non_temporal_threshold m= ay > > be set to less than the minimum value when the shared cache size isn't > > available (e.g., in an emulator) or by the tunable. Add checks for > > minimum and maximum of non_temporal_threshold. > > > > This fixes BZ #29953. > > --- > > sysdeps/x86/dl-cacheinfo.h | 25 ++++++++++++++++--------- > > 1 file changed, 16 insertions(+), 9 deletions(-) > > > > diff --git a/sysdeps/x86/dl-cacheinfo.h b/sysdeps/x86/dl-cacheinfo.h > > index e9f3382108..637b5a022d 100644 > > --- a/sysdeps/x86/dl-cacheinfo.h > > +++ b/sysdeps/x86/dl-cacheinfo.h > > @@ -861,6 +861,18 @@ dl_init_cacheinfo (struct cpu_features *cpu_featur= es) > > share of the cache, it has a substantial risk of negatively > > impacting the performance of other threads running on the chip. *= / > > unsigned long int non_temporal_threshold =3D shared * 3 / 4; > > + /* SIZE_MAX >> 4 because memmove-vec-unaligned-erms right-shifts the= value of > > + 'x86_non_temporal_threshold' by `LOG_4X_MEMCPY_THRESH` (4) and it= is best > > + if that operation cannot overflow. Minimum of 0x4040 (16448) beca= use the > > + L(large_memset_4x) loops need 64-byte to cache align and enough s= pace for > > + at least 1 iteration of 4x PAGE_SIZE unrolled loop. Both values = are > > + reflected in the manual. */ > > + unsigned long int maximum_non_temporal_threshold =3D SIZE_MAX >> 4; > > + unsigned long int minimum_non_temporal_threshold =3D 0x4040; > > + if (non_temporal_threshold < minimum_non_temporal_threshold) > > + non_temporal_threshold =3D minimum_non_temporal_threshold; > > + else if (non_temporal_threshold > maximum_non_temporal_threshold) > > + non_temporal_threshold =3D maximum_non_temporal_threshold; > > > > #if HAVE_TUNABLES > > /* NB: The REP MOVSB threshold must be greater than VEC_SIZE * 8. *= / > > @@ -915,8 +927,8 @@ dl_init_cacheinfo (struct cpu_features *cpu_feature= s) > > shared =3D tunable_size; > > > > tunable_size =3D TUNABLE_GET (x86_non_temporal_threshold, long int, = NULL); > > - /* NB: Ignore the default value 0. */ > > - if (tunable_size !=3D 0) > > + if (tunable_size > minimum_non_temporal_threshold > > + && tunable_size <=3D maximum_non_temporal_threshold) > > non_temporal_threshold =3D tunable_size; > > > > tunable_size =3D TUNABLE_GET (x86_rep_movsb_threshold, long int, NUL= L); > > @@ -931,14 +943,9 @@ dl_init_cacheinfo (struct cpu_features *cpu_featur= es) > > > > TUNABLE_SET_WITH_BOUNDS (x86_data_cache_size, data, 0, SIZE_MAX); > > TUNABLE_SET_WITH_BOUNDS (x86_shared_cache_size, shared, 0, SIZE_MAX)= ; > > - /* SIZE_MAX >> 4 because memmove-vec-unaligned-erms right-shifts the= value of > > - 'x86_non_temporal_threshold' by `LOG_4X_MEMCPY_THRESH` (4) and it= is best > > - if that operation cannot overflow. Minimum of 0x4040 (16448) beca= use the > > - L(large_memset_4x) loops need 64-byte to cache align and enough s= pace for > > - at least 1 iteration of 4x PAGE_SIZE unrolled loop. Both values = are > > - reflected in the manual. */ > > TUNABLE_SET_WITH_BOUNDS (x86_non_temporal_threshold, non_temporal_th= reshold, > > - 0x4040, SIZE_MAX >> 4); > > + minimum_non_temporal_threshold, > > + maximum_non_temporal_threshold); > > TUNABLE_SET_WITH_BOUNDS (x86_rep_movsb_threshold, rep_movsb_threshol= d, > > minimum_rep_movsb_threshold, SIZE_MAX); > > TUNABLE_SET_WITH_BOUNDS (x86_rep_stosb_threshold, rep_stosb_threshol= d, 1, > > -- > > 2.39.0 > > > > LGTM. I am backporting this to release branches. --=20 H.J.