Pullback of the canonical divisor between smooth varieties I have a surjective morphism $\pi: Y \to X$ between smooth projective varieties of the same dimension over some algebraically closed field $k$. Debarre claims in his book "Higher-Dimensional Algebraic Geometry" (1.41) that there is an effective divisor $R$ such that
$$ K_Y \equiv \pi^* K_X + R$$
if $K(X) \subset K(X)$ is a separable field extension. In particular, this is always true if $\pi$ is birational. Debarre also claims that in this case the support of $R$ is the exceptional locus.
I search for a reference for this fact because Debarre does not provide one. I'm in particular interested in the case of positive characteristic. In characteristic $0$ this is a well known fact and I would like to confirm that it is still fine in positive characteristic.
 A: A down-to-earth approach can be the following. 
Assume that the morphism $\pi \colon X \to Y$ is separable; then it is unramified on an open dense subset of $X$ and we have a short exact sequence of tangent sheaves
$$0 \to T_X \stackrel{d \pi}{\to} \pi^*T_Y \to N_f \to 0,$$
where $N_f$ is a sheaf supported on the ramification divisor of $\pi$, see [Sernesi, Deformation Theory, page 162].
Dualizing the sequence above we obtain
$$0 \to \pi^*\Omega^1_Y \to \Omega^1_X \to \mathcal{E}xt^1(N_f, \mathcal{O}_X) \to 0,$$
where $\mathcal{E}xt^1(N_f, \mathcal{O}_X)$ is again supported on the ramification divisor of $\pi$.
The identity you are looking for (and which is sometimes called Hurwitz formula) now follows by just taking the  $n$-th exterior powers, with $n=\dim X = \dim Y$.
A: It is a consequence of general Grothendieck duality, but you are probably looking for a down-to-earth reference. I suggest you to look at
Kleiman, S. L.: 
The enumerative theory of singularities.
in: Real and complex singularities (Proc. Ninth Nordic Summer School/NAVF Sympos. Math., Oslo, 1976), pp. 297–396. Sijthoff and Noordhoff, Alphen aan den Rijn, 1977. (MR 58 #27960)
where it follows from the first fundamental exact sequence for sheaves of differentials.
The formula you look for is (I, 16) on page 303 and it is stated for a surjective separable map between smooth varieties of the same dimension. It is written in terms of sheaves, but they are invertible so the formula follows immediately.
A: EDIT Originally I claimed a more general statement and along the incremental generalizations I reached a statement that was not true. Thanks to Carlos for pointing out this error! So, I thought it would be fair to point out where the error lied.
The main issue is that the original proof works for a finite morphism, but not if there are exceptional divisors, because then on the target the localization would not happen at a height $1$ prime. In order to preserve the original proof, here is a fix that divides the statement into two parts.
0

By Stein factorization it is enough to prove the statement for finite or birational morphisms.

1

Thm Let $\pi:Y\to X$ be a separable projective finite morphism between normal varieties of the same dimension. Assume that $K_X$ is a $\mathbb Q$-Cartier divisor (i.e., there exists an $m\in \mathbb N_+$ such that $mK_X$ is a Cartier divisor). Then there exists an effective divisor $R\subset Y$ whose support is contained in the ramification locus of $\pi$ (that is, the complement of the largest open subset of $Y$ on which $\pi$ is smooth) such that 
  $$K_Y\sim \pi^*K_X + R.$$

Proof:
We need to prove that the divisor $\pi^*K_X-K_Y$ is linearly equivalent to an effective divisor supported on the exceptional locus . This can be done by localizing at height $1$ primes, so the question reduces to a question about regular schemes of dimension $1$. One may apply the usual proof of the Hurwitz formula:
Consider the short exact sequence $$0\to \pi^*\Omega_X\to \Omega_Y\to \Omega_{Y/X}\to 0$$
and observe that $\Omega_{Y/X}$ is a torsion sheaf whose support is the ramification locus (this is where you need that the map is separable), which in this case is the same as the exceptional divisor (the smaller parts of the exceptional locus disappear at the localization). This is a finite set, so $\Omega_{X/Y}$ maybe considered as the structure sheaf of a finite subscheme of $Y$. Let $R\subseteq Y$ be this subscheme. Tensoring the above short exact sequence by $\Omega_Y^{-1}$ gives:
$$ 0\to \pi^*\Omega_X\otimes \Omega_Y^{-1}\to \mathscr O_Y \to \mathscr O_R \to 0,$$
which shows that $\pi^*\Omega_X\otimes \Omega_Y^{-1}\simeq \mathscr O_Y(-R)$. This implies the needed linear equivalence.
To find the original $R$ all you need to do is to take the divisor that localizes to the $R$ we found in the $1$-dimensional case. Since we're talking about divisors the codimension $2$ ambiguity makes no difference. 
2

Thm Let $\pi:Y\to X$ be a projective birational morphism between smooth varieties. Then there exists an effective divisor $R\subset Y$ whose support is the exceptional locus $E\subseteq Y$ of $\pi$ such that 
  $$K_Y\sim \pi^*K_X + R.$$

Proof: 
Consider (again) the short exact sequence $$0\to \pi^*\Omega_X\to \Omega_Y\to \Omega_{Y/X}\to 0$$
and notice that $\pi$ is an isomorphism on $Y\setminus E$, so similarly $\pi^*\Omega_X\to \Omega_Y$ is an isomorphism there. Now take the determinant of these locally free sheaves and conclude that $\pi^*\omega_X\subseteq\omega_Y$ and $\omega_Y/f^*\omega_X$ is supported on $E$. This implies that the divisor $K_Y-f^*K_X$ is an effective divisor supported on $E$.
We need to prove that the support of $R$ is the entire $E$. For this, first notice that in order to prove the desired statement, using what we have proved already, we may pass to another birational model that dominates $Y$. (The point is that a $\pi$-exceptional divisor will be exceptional for the combined map to $X$ but not for the map to $Y$.) Second, a theorem of Zariski says that every exceptional divisor can be reached by a sequence of blow-ups (see Kollár-Mori98, 2.45). We know how to compute the canonical divisor of a blow-up and we know that the entire exceptional locus is contained in the discrepancy divisor, so   the desired statement follows.
3
Comment The reason the second part requires smoothness is that one needs $\Omega_X$ to be locally free so when pulled back it would give the right thing. Otherwise it might pick up torsion or co-torsion. The statement is true in a little bit more general situation, if $X$ has at worst canonical singularities, but that is essentially the definition of those singularities and this statement says that smooth points are canonical, so it is a reasonable condition to use to define singularities.
