From nobody Wed Aug 24 19:25:09 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MCbdx5Zx7z4Zfhw; Wed, 24 Aug 2022 19:25:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MCbdx51Clz3PXP; Wed, 24 Aug 2022 19:25:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661369109; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LJvtLS9R7F/07SrlFqjkw88pQImcIJdV8OONDF0afa8=; b=UsJoldHo0Or3CaGHDO3r5p3bjfwp+tyUI0FmTfTAHrqUBEGpuWwIwXSh4JVLOz2UeyYx4p 41ifhWgAgAuffZODiAomb0T55BGmAXYJJUnFdFVPwHjC5dC0+FYi5zlUfyr/6ck65PCin0 dCJ90krWgS5l7GjKldxz/x6Oc+cQfoDcCsSvUjKubQx1PSsBKBx/VxnM5eGrx7peCTAr+G PnCw5JwI0KOsgZh+nhpduUVvln311K9caY870utegylVJxUxGT3MjEnDEuW3dQWMPdhFKA Fpt9i8Z6blyMhQo+EoQAb/acJngzQEz9kcqL8E/cVy3td7MaCjD99dAKMoQhIg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MCbdx3zgmzLFF; Wed, 24 Aug 2022 19:25:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 27OJP9WJ069092; Wed, 24 Aug 2022 19:25:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27OJP9Fh069091; Wed, 24 Aug 2022 19:25:09 GMT (envelope-from git) Date: Wed, 24 Aug 2022 19:25:09 GMT Message-Id: <202208241925.27OJP9Fh069091@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 95f773e59482 - main - i386 copyout_fast: improve detection of a fault on accessing userspace List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 95f773e59482b1a3462d2fe3901532d51fb053b3 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661369109; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LJvtLS9R7F/07SrlFqjkw88pQImcIJdV8OONDF0afa8=; b=UyHbKf0ZGALIAv24oTWmVdXtlB18aBdGm6IszOBEASQkpcLBuEucW/WuZVJUYm2t41P2ir Qx9vGqHqh5C7AHwZSmDnWRhmR6JNb+SdBP6T8XQ6bCpNcO6TgIyDZp3M/FvGGAniz4LIDt j6o+6g8FyDv57i+tYIsZM5M3i95r0laRj+FEG/h62ntKrT+OIvLx9zRsZTUevXwO7HNOZQ XNuODPN7y9YxbTQbotOe9AGDWHAnhUIDAuV8gq1elLTXQsibFpGTBqsxkLAKWzpBHgaqqB Yji2hxTT/9/g+Gbxd9LGht7C92P5TpLDZDeLg1xRRXWWAAfUSkerslNUh74tog== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1661369109; a=rsa-sha256; cv=none; b=MW9GPs/MlGj+pU5HMZ+ncm2gClxX67WNBR0J7Nz9zFw9AYhpb1nb/OaifLOMOU6nysUZ7C yDju365HO/XvxrcWn/WWYYd6V7V83kK1uYAPUh3NKLsJKf1KhN1xlJRJFVWcPjqKOcJUNt MywHQR5x6Is8Vxw6Ri/f/+1rWs2A8b5x6q3fHTyYeDZ3UV+qFggQTqrQJRAhv17ja7I2BB tcyz32ysFIvYWLyWP7DxI75WOCsyeR351eCPiyppHANpW1gRySXh76lvwsIHPf/BGT8JT5 V1axBce2S5J8av9eLxe2sBPL+tJJKfXfeYeikch7rXuYSd25u+9pSC70ECt48A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=95f773e59482b1a3462d2fe3901532d51fb053b3 commit 95f773e59482b1a3462d2fe3901532d51fb053b3 Author: Konstantin Belousov AuthorDate: 2022-08-09 00:56:54 +0000 Commit: Konstantin Belousov CommitDate: 2022-08-24 19:11:40 +0000 i386 copyout_fast: improve detection of a fault on accessing userspace Do not blindly account a page fault occuring on the trampoline area, as the userspace access fault. Check that it occured exactly in the instruction that does that. This avoids unneeded switches of address space on faults not needing the switch, effectively converting machine resets due to tripple faults, into regular panics. Reviewed by: jhb Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D36302 --- sys/i386/i386/copyout_fast.s | 16 ++++++++-------- sys/i386/i386/exception.s | 32 ++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/sys/i386/i386/copyout_fast.s b/sys/i386/i386/copyout_fast.s index 715952f5fe20..d1d17f775872 100644 --- a/sys/i386/i386/copyout_fast.s +++ b/sys/i386/i386/copyout_fast.s @@ -93,7 +93,7 @@ ENTRY(copyout_fast) popl %ecx popl %edi popl %esi - rep; movsb +pf_x1: rep; movsb movl %ebx,%cr3 movl %eax,%esp @@ -150,7 +150,7 @@ ENTRY(copyin_fast) popl %ecx popl %edi popl %esi - rep; movsb +pf_x2: rep; movsb movl %ebx,%cr3 @@ -197,7 +197,7 @@ ENTRY(fueword_fast) cli movl PCPU(TRAMPSTK),%esp movl %eax,%cr3 - movl (%ecx),%eax +pf_x3: movl (%ecx),%eax movl %ebx,%cr3 movl %esi,%esp sti @@ -226,7 +226,7 @@ ENTRY(fuword16_fast) cli movl PCPU(TRAMPSTK),%esp movl %eax,%cr3 - movzwl (%ecx),%eax +pf_x4: movzwl (%ecx),%eax movl %ebx,%cr3 movl %esi,%esp sti @@ -252,7 +252,7 @@ ENTRY(fubyte_fast) cli movl PCPU(TRAMPSTK),%esp movl %eax,%cr3 - movzbl (%ecx),%eax +pf_x5: movzbl (%ecx),%eax movl %ebx,%cr3 movl %esi,%esp sti @@ -291,7 +291,7 @@ ENTRY(suword_fast) cli movl PCPU(TRAMPSTK),%esp movl %eax,%cr3 - movl %edi,(%ecx) +pf_x6: movl %edi,(%ecx) movl %ebx,%cr3 movl %esi,%esp sti @@ -319,7 +319,7 @@ ENTRY(suword16_fast) cli movl PCPU(TRAMPSTK),%esp movl %eax,%cr3 - movw %di,(%ecx) +pf_x7: movw %di,(%ecx) movl %ebx,%cr3 movl %esi,%esp sti @@ -348,7 +348,7 @@ ENTRY(subyte_fast) movl PCPU(TRAMPSTK),%esp movl %eax,%cr3 movl %edi,%eax - movb %al,(%ecx) +pf_x8: movb %al,(%ecx) movl %ebx,%cr3 movl %esi,%esp sti diff --git a/sys/i386/i386/exception.s b/sys/i386/i386/exception.s index f4135548fd81..42e9c474c3cd 100644 --- a/sys/i386/i386/exception.s +++ b/sys/i386/i386/exception.s @@ -130,17 +130,41 @@ IDTVEC(prot) jmp irettraps IDTVEC(page) testl $PSL_VM, TF_EFLAGS-TF_ERR(%esp) - jnz 1f + jnz 4f testb $SEL_RPL_MASK, TF_CS-TF_ERR(%esp) - jnz 1f + jnz 4f cmpl $PMAP_TRM_MIN_ADDRESS, TF_EIP-TF_ERR(%esp) - jb 1f + jb 4f + pushl %eax + movl TF_EIP-TF_ERR+4(%esp), %eax + addl $1f, %eax + call 5f +1: cmpl $pf_x1, %eax + je 2f + cmpl $pf_x2, %eax + je 2f + cmpl $pf_x3, %eax + je 2f + cmpl $pf_x4, %eax + je 2f + cmpl $pf_x5, %eax + je 2f + cmpl $pf_x6, %eax + je 2f + cmpl $pf_x7, %eax + je 2f + cmpl $pf_x8, %eax + jne 3f +2: popl %eax movl %ebx, %cr3 movl %edx, TF_EIP-TF_ERR(%esp) addl $4, %esp iret -1: pushl $T_PAGEFLT +3: popl %eax +4: pushl $T_PAGEFLT jmp alltraps +5: subl (%esp), %eax + retl IDTVEC(rsvd_pti) IDTVEC(rsvd) pushl $0; TRAP(T_RESERVED)