From patchwork Tue Jan 9 16:46:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 186463 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp237647dyi; Tue, 9 Jan 2024 08:47:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IEw9FPo48z1NEOxJYRARgbR3nNRlpDvN2zOtdzAJOTNVjK90xQ1ENeeryB0Qc8npTDYeli0 X-Received: by 2002:a81:5d43:0:b0:5d7:1941:aba with SMTP id r64-20020a815d43000000b005d719410abamr4214869ywb.85.1704818879515; Tue, 09 Jan 2024 08:47:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704818879; cv=pass; d=google.com; s=arc-20160816; b=QKdvsB2b0kO7CHJsDahTvAyHDSi4mzERNuxDKp2F4bJv4g7M02J1fLsC+q7CdHokh8 TMEjSx1T8Q64Tw+CYy53o5h7x8/x6R5Vch5yDFHuJbrOr9B05OO4zFbFhsZR/Bzv7dEq ClqlUE03b4tVTqAPZYEX6Wz6PIQfY/5aebJ6OT8D49BGwjMZiJze5Q35XC13x7lIn+hC W2j4F4nzP/Et3WUYNI5YMxR4TZipMpPb4XZ2B/6DjLo8kf+iW9E5dV8BOxRs6mkqLems WvPPDZM6A/2WOuH2bRZtgCMTVFffgsn0d0j6sT2zP/uz6wuMisoqYYhYsdOTtvoYNYA1 Vkxw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=p8KP9rY0rgIFaUlOkttfMkpBWFr7vteH5IWUBBsCUxI=; fh=+XL94kVD9/tYL0GMhl5gIpPvSPBgbUiYWmKn21tcEQo=; b=hRTiyqgYXJbeI43lY2Wb9FwYePHucSzWQYLK4irxC8yPmwqCte38HgSSLuldDs7PBY jlrWCxXgckYnKMW3UMNYAL8gfPSaPeUMUSa/Drkz/eQYCjAD9R3T/06RYk8cfoTZTIrs L+gnP/snJqjPOAv+o7kSurY29ES+DnPKYIc2r/w8H8oY0o9RHY8Etbt+Nk6rLYBzKqv7 /beS8MtcelyEieekf4AFK63i/gbOqmT7Qhdi6s+hI3Qw2+qIeTur70oVQCLK0CHDJxYe OBAalMHFUXgpljqvRSulb9FC/JQr8k3zUOsqXSy9procvfppiBrH8CpvA3P/1C36jzLt difg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TI79SFjg; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id s1-20020a0ce301000000b00680ce50b84bsi2596414qvl.567.2024.01.09.08.47.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 08:47:59 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TI79SFjg; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ADEE9385B532 for ; Tue, 9 Jan 2024 16:47:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 6219A3857C74 for ; Tue, 9 Jan 2024 16:47:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6219A3857C74 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6219A3857C74 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704818825; cv=none; b=PIP9bF1yYS7uSVjkE2rm8hPdVcU/BOt/KFvckY/GbjYeEQAdd6v54MBnG4ofB7Awy9lAyHSN421jdA5MHZWmnjAV/j65Zpt0H3F0iLGzz2IGfDaJn+/kIMyoJ0c0F1Akq1TEvu0LWPr42RutcTtJjy95fQ1xsNcps9dMcjNrJA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704818825; c=relaxed/simple; bh=1w9TzngKBNiu/7rw204GhlkAFtQpezl5UP7tdtreh3E=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=m56MmWyyTsfCbdQBx6ngR7+dc10RUb5ECvp6DyDwB+DudbfhfNl6y9oIyMoBBUMhpCpHGghMUww1lfk5Mb+yNRukUSoAaznYkEDfo4QNe51w4Pt8tRHXWp60fShd/siRueYb1km34yviCshorPeBxNTaFJvjmhVCwn4W8DwssWk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6d9bd63ec7fso1564994b3a.2 for ; Tue, 09 Jan 2024 08:47:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704818821; x=1705423621; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=p8KP9rY0rgIFaUlOkttfMkpBWFr7vteH5IWUBBsCUxI=; b=TI79SFjgkfIXy+dcFRxHSqvnTve7zwP5UN8QCuVGJrZBaNblRzDjudyDEoh5PD4ONd 6rjRJPxZ4x0ZZCeK1uks735p2fUUtPNYOmrzLw4VWozhlLfE9/Nhf3X9pHFFPhb6cLv7 3sqN7E5+2Ue25lRRs2xG3JI33v3RIiYtFP7jImdpEaiK9xMWQn67lY85KY93lHie5rJA SvpM69YtnLXFehtCF6nNOKLb4A3Ub6s3my2D2a7ZwfWU8yMIbMKuL68ZHhJkaROMRmwD qIZx1Lo+ls2a7dP26Fkb3pMlgXDt9GD0FN167dlXpemEUSjUHO2ZaEDn3sCh9hnAXGz4 MSrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704818821; x=1705423621; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=p8KP9rY0rgIFaUlOkttfMkpBWFr7vteH5IWUBBsCUxI=; b=oqWdbhF0ZWQTS83y4b7oTV/6ChqJm26SZ36vFJ5RuRyAYN+uIoT8S+fD1KV+AO2Rte vYSf+Kwv0kGwX8QU5Fo1mJahJyevCpo7o5z61CojZYXI1cz865PBwpvFmJTRf2WKXh9g BVd0t8XvLCZnJmEXLzerMHwh5GgObADRaFW6DViadZKRylFcB1hjVmJfyA1JcsK+jclZ aNSORYaCpB0TfyicmUlQBDzJ4zLasq6LNosX8pnlLDlqKz6ktiGNTW3crOljqvU0oS84 59FfyXKZu/zZCKViudX1fTMMyBciJQ9CXbicXQKoaAxmy6Uzlcc6zsF/rWRlWji3GCva 0LNg== X-Gm-Message-State: AOJu0YyML8q522G89bSzkhOZByt4EbnH6FnaK5WsD5sM4WGM3L8Cqbbp a5a+Fj/HaCV+NEcaR0eZx0JMls6jjjA= X-Received: by 2002:a62:e918:0:b0:6d9:d29c:8782 with SMTP id j24-20020a62e918000000b006d9d29c8782mr2590573pfh.20.1704818820936; Tue, 09 Jan 2024 08:47:00 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.169.119]) by smtp.gmail.com with ESMTPSA id v66-20020a626145000000b006d9ac70682bsm1964593pfb.167.2024.01.09.08.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 08:47:00 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 1C306740178; Tue, 9 Jan 2024 08:46:59 -0800 (PST) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: crazylht@gmail.com Subject: [PATCH] hwasan: Check if Intel LAM_U57 is enabled Date: Tue, 9 Jan 2024 08:46:59 -0800 Message-ID: <20240109164659.1822407-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3024.3 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787632161762017901 X-GMAIL-MSGID: 1787632161762017901 When -fsanitize=hwaddress is used, libhwasan will try to enable LAM_U57 in the startup code. Update the target check to enable hwaddress tests if LAM_U57 is enabled. Also compile hwaddress tests with -mlam=u57 on x86-64 since hwasan requires LAM_U57 on x86-64. * lib/hwasan-dg.exp (check_effective_target_hwaddress_exec): Return 1 if Intel LAM_U57 is enabled. (hwasan_init): Add -mlam=u57 on x86-64. --- gcc/testsuite/lib/hwasan-dg.exp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/lib/hwasan-dg.exp b/gcc/testsuite/lib/hwasan-dg.exp index e9c5ef6524d..76057502ee6 100644 --- a/gcc/testsuite/lib/hwasan-dg.exp +++ b/gcc/testsuite/lib/hwasan-dg.exp @@ -44,11 +44,25 @@ proc check_effective_target_hwaddress_exec {} { #ifdef __cplusplus extern "C" { #endif + extern int arch_prctl (int, unsigned long int *); extern int prctl(int, unsigned long, unsigned long, unsigned long, unsigned long); #ifdef __cplusplus } #endif int main (void) { + #ifdef __x86_64__ + # ifdef __LP64__ + # define ARCH_GET_UNTAG_MASK 0x4001 + # define LAM_U57_MASK (0x3fULL << 57) + unsigned long mask = 0; + if (arch_prctl(ARCH_GET_UNTAG_MASK, &mask) != 0) + return 1; + if (mask != ~LAM_U57_MASK) + return 1; + return 0; + # endif + return 1; + #else #define PR_SET_TAGGED_ADDR_CTRL 55 #define PR_GET_TAGGED_ADDR_CTRL 56 #define PR_TAGGED_ADDR_ENABLE (1UL << 0) @@ -58,6 +72,7 @@ proc check_effective_target_hwaddress_exec {} { || !prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0)) return 1; return 0; + #endif } }] { return 0; @@ -102,6 +117,10 @@ proc hwasan_init { args } { setenv HWASAN_OPTIONS "random_tags=0" + if [istarget x86_64-*-*] { + set target_hwasan_flags "-mlam=u57" + } + set link_flags "" if ![is_remote host] { if [info exists TOOL_OPTIONS] { @@ -119,12 +138,12 @@ proc hwasan_init { args } { if [info exists ALWAYS_CXXFLAGS] { set hwasan_saved_ALWAYS_CXXFLAGS $ALWAYS_CXXFLAGS set ALWAYS_CXXFLAGS [concat "{ldflags=$link_flags}" $ALWAYS_CXXFLAGS] - set ALWAYS_CXXFLAGS [concat "{additional_flags=-fsanitize=hwaddress --param hwasan-random-frame-tag=0 -g $include_flags}" $ALWAYS_CXXFLAGS] + set ALWAYS_CXXFLAGS [concat "{additional_flags=-fsanitize=hwaddress $target_hwasan_flags --param hwasan-random-frame-tag=0 -g $include_flags}" $ALWAYS_CXXFLAGS] } else { if [info exists TEST_ALWAYS_FLAGS] { - set TEST_ALWAYS_FLAGS "$link_flags -fsanitize=hwaddress --param hwasan-random-frame-tag=0 -g $include_flags $TEST_ALWAYS_FLAGS" + set TEST_ALWAYS_FLAGS "$link_flags -fsanitize=hwaddress $target_hwasan_flags --param hwasan-random-frame-tag=0 -g $include_flags $TEST_ALWAYS_FLAGS" } else { - set TEST_ALWAYS_FLAGS "$link_flags -fsanitize=hwaddress --param hwasan-random-frame-tag=0 -g $include_flags" + set TEST_ALWAYS_FLAGS "$link_flags -fsanitize=hwaddress $target_hwasan_flags --param hwasan-random-frame-tag=0 -g $include_flags" } } }